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 |
WHY 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[1]=0; Q.push(node(1,0)); while(!Q.empty()) { te=Q.top(); Q.pop(); if(dis[te.v]!=te.w)continue; if(te.v==n||te.w==INF)return; 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; fount=0; 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; } 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