标签:desc else string 思路 col bsp ssi 起点 namespace
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 30385 Accepted Submission(s):
8985
#include<iostream> #include<cstring> using namespace std; const int INF = 0x3f3f3f3f; const int M = 1009; int n,m,vis[M],dist[M],ans[M],minn,g[M][M],i,j,u,a,b,d,p,s,e,v[M][M]; void dij(){ for(i=0;i<=n;i++){ dist[i] = INF; vis[i] = 0; } dist[s] = 0; ans[s] = 0; int n1 = n; while(n1--){ int minn = INF; for(i=1;i<=n;i++){ if(!vis[i]&&minn>dist[i]){ minn = dist[i]; u = i; } } vis[u] = 1; for(i=1;i<=n;i++){ if(!vis[i]&&dist[i]>dist[u]+g[u][i]){ dist[i] = dist[u] + g[u][i]; ans[i] = ans[u] + v[u][i]; } else if(!vis[i]&&dist[i]==dist[u]+g[u][i]){ ans[i] = min(ans[i],ans[u]+v[u][i]); } } } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); while(cin>>n>>m){ memset(g,INF,sizeof(g)); memset(v,INF,sizeof(v)); if(n==0&&m==0) break; for(i=0;i<=n;i++){ for(j=0;j<=n;j++){ if(i==j) g[i][j] = 0; else g[i][j] = INF; } } for(i=1;i<=m;i++){ cin>>a>>b>>d>>p; if(g[a][b]>=d){ g[a][b] = g[b][a] = d; v[a][b] = v[b][a] = p; } } cin>>s>>e; dij(); cout<<dist[e]<<" "<<ans[e]<<endl; } }
标签:desc else string 思路 col bsp ssi 起点 namespace
原文地址:http://www.cnblogs.com/kls123/p/7773233.html