标签:blog name field des acm sub == mil jks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 29549 Accepted Submission(s): 8761
#include <cstdio> #include <iostream> #include <cstring> #include <map> #include <algorithm> using namespace std; #define INF 0x3f3f3f3f int path [1010][1010]; int cost[1010][1010]; int s,t,n,m,u,v,val,long1; int dis[1010]; int co[1010]; int vis[1010]; void djs(int s,int t) { fill(co,co+n+1,INF); fill(dis,dis+n+1,INF); co[s]=0; dis[s]=0; while(1) { int u=-1; for(int i=1;i<=n;i++) if(!vis[i]&&(u==-1||dis[i]<dis[u]))u=i; if(u==-1)break; vis[u]=1; for(int i=1;i<=n;i++) { if(path[u][i]==-1)continue; if(dis[i]>dis[u]+path[u][i]) { dis[i]=dis[u]+path[u][i]; co[i]=co[u]+cost[u][i]; } else if(dis[i]==dis[u]+path[u][i]) co[i]=min(co[i],co[u]+cost[u][i]); } } } int main() { while(scanf("%d%d",&n,&m)!=EOF) { if(n==0&&m==0)break; memset(path,-1,sizeof(path)); memset(cost,-1,sizeof(cost)); memset(vis,0,sizeof(vis)); for(int i=0;i<m;i++) { scanf("%d%d%d%d",&u,&v,&long1,&val); if(long1<path[u][v]||path[u][v]==-1){ path[u][v]=long1; cost[u][v]=val; path[v][u]=long1; cost[v][u]=val; } } scanf("%d%d",&s,&t); djs(s,t); printf("%d %d\n",dis[t],co[t]); } return 0; }
标签:blog name field des acm sub == mil jks
原文地址:http://www.cnblogs.com/a249189046/p/7488776.html