有兩個權值,距離相等的時候判斷一下花費
3 2 1 2 5 6 2 3 4 5 1 3 0 0
9 11
#include#include #include #include using namespace std; const int maxn=1100; const int INF=0x3f3f3f3f; int c[maxn][maxn],w[maxn][maxn]; int n,m; int origional,vis[maxn],dist[maxn],cost[maxn]; void dijkstra() { memset(vis,0,sizeof(vis)); memset(dist,63,sizeof(dist)); memset(cost,63,sizeof(cost)); cost[origional]=dist[origional]=0; for(int l=0;l dist[i]) { mark=i; mindist=dist[i]; } } vis[mark]=1; for(int i=1;i<=n;i++) { if(vis[i]) continue; if(dist[i]>dist[mark]+w[mark][i]) { dist[i]=dist[mark]+w[mark][i]; cost[i]=cost[mark]+c[mark][i]; } else if(dist[i]==dist[mark]+w[mark][i]&&cost[i]>cost[mark]+c[mark][i]) { cost[i]=cost[mark]+c[mark][i]; } } } } int main() { while(scanf("%d%d",&n,&m)!=EOF) { if(n==0&&m==0) break; memset(c,63,sizeof(c)); memset(w,63,sizeof(w)); int a,b,d,p; for(int i=0;i