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 |
哪位大牛帮忙看下,为何一直wa啊!!#include <stdio.h> #include <iostream> #include <algorithm> #include <queue> #define M 10120 #define inf 0x3f3f3f3f using namespace std; queue<pair<int ,int > > Q; int max1; int e,end[M],head[M],next[M],cost[M],length[M]; inline void Init(){ e=0; memset(head,-1,sizeof(head)); } inline void add(int u,int v,int l,int w){ end[e]=v; cost[e]=w; length[e]=l; next[e]=head[u]; head[u]=e++; } int dis[101][M],vis[101][M],cnt[101][M]; void spfa(int n){ memset(dis,inf,sizeof(dis)); memset(vis,0,sizeof(vis)); while(!Q.empty()) Q.pop(); dis[1][0]=0; vis[1][0]=1; Q.push(make_pair(1,0)); while(!Q.empty()){ int u=Q.front().first; int mo=Q.front().second; Q.pop(); vis[u][mo]=0; for(int i=head[u];i!=-1;i=next[i]){ int v=end[i],w=cost[i],le=length[i]; if(dis[v][mo+w]>le+dis[u][mo]){ dis[v][mo+w]=le+dis[u][mo]; if(!vis[v][mo+w]){ vis[v][mo+w]=1; Q.push(make_pair(v,mo+w)); } } } } } int main(){ int n,m; cin>>max1>>n>>m; Init(); int u,v,w,l; while(m--){ scanf("%d%d%d%d",&u,&v,&l,&w); add(u,v,l,w); } spfa(n); int p=inf; int t; for(int i=0;i<=max1;i++){ if(p>dis[n][i]) p=dis[n][i]; } if(p==inf) printf("-1\n"); else printf("%d\n",p); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator