Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
找到t后返回为什么回WA?(不是重边的问题)#include <iostream> #include <vector> #include <queue> #include <algorithm> using namespace std; #define INF (1<<30) #define N 30005 int dis[N]; struct node { int v,w; node(){} node(int vv,int ww){v=vv;w=ww;} bool operator<(const node & o)const { return dis[v]>dis[o.v]; } }; struct e { int v,w,next; }E[150005]; int fount; int head[N]; int rear[N]; void dijkstra(int s,int t,int n) { priority_queue <node> Q; int v,w,ite; node te; fill(dis,dis+n+1,INF); dis[s]=0; Q.push(node(s,0)); while(!Q.empty()) { te=Q.top(); Q.pop(); if(dis[te.v]!=te.w)continue; if(te.v==t)return;//这行去掉就AC,真搞不懂啊!!!知道的大牛email给我,谢谢了 for(ite=head[te.v];ite!=-1;ite=E[ite].next) { v=E[ite].v; w=E[ite].w; if(dis[te.v]+w<dis[v]) { dis[v]=dis[te.v]+w; Q.push(node(v,dis[v])); } } } } int main() { int s,t,w,n,m; cin>>n>>m; memset(head,-1,sizeof(head)); for(fount=0;fount<m;++fount) { scanf("%d%d%d",&s,&t,&w); E[fount].v=t; E[fount].w=w; E[fount].next=-1; if(head[s]==-1) head[s]=fount; else E[ rear[s] ].next=fount; rear[s]=fount; } dijkstra(1,n,n); cout<<dis[n]<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator