标签:printf 输出 分享 panel cos class weight 12px pop
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 33536 Accepted Submission(s): 9835
#include<cstdio> #include<cstring> #include<algorithm> #include<queue> #define INF 999999999 using namespace std; struct Node{ int s,t,c,q; }edge[200000]; int N,M; int next1[200000],head[2000]; int d[2000],vis[2000],cost[2000]; int S,T,cnt; void spfa() { for(int i=0;i<=N;i++) {vis[i]=0;d[i]=INF;cost[i]=INF;} vis[S]=1;d[S]=0;cost[S]=0; queue<int> q; q.push(S); while(!q.empty()) { int v=q.front(); q.pop();vis[v]=0; int k=head[v]; while(k!=-1) { int b=edge[k].t; if(d[b]>d[v]+edge[k].c) { cost[b]=cost[v]+edge[k].q; d[b]=d[v]+edge[k].c; if(!vis[b]) { vis[b]=1; q.push(b); } } else if(d[b]==d[v]+edge[k].c&&cost[b]>cost[v]+edge[k].q) { cost[b]=cost[v]+edge[k].q; if(!vis[b]) { vis[b]=1; q.push(b); } } k=next1[k]; } } } void Add(int a,int b,int c,int q) { edge[cnt].s=a;edge[cnt].t=b; edge[cnt].c=c;edge[cnt].q=q; next1[cnt]=head[edge[cnt].s]; head[edge[cnt].s]=cnt; cnt++; } int main() { while(scanf("%d%d",&N,&M)!=-1) { if(!N&&!M) break; memset(head,-1,sizeof(head)); cnt=1; for(int i=1;i<=M;i++) { int a,b,c,q; scanf("%d%d%d%d",&a,&b,&c,&q); Add(a,b,c,q); Add(b,a,c,q); } scanf("%d%d",&S,&T); spfa(); printf("%d %d\n",d[T],cost[T]); } return 0; }
标签:printf 输出 分享 panel cos class weight 12px pop
原文地址:https://www.cnblogs.com/ACRykl/p/9103805.html