标签:turn mem while href com problems for ack bre
int dis[500][500]; int cost[500][500]; int pre[500]; int mindis[500]; int mincost[500]; int inque[500]; int main(){ memset(dis,-1,sizeof(dis)); int N,M,S,D; cin>>N>>M>>S>>D; int u,v,d,c; for(int i=0;i<M;i++){ cin>>u>>v>>d>>c; dis[u][v]=d; dis[v][u]=d; cost[u][v]=c; cost[v][u]=c; } for(int i=0;i<500;i++) mindis[i]=INT_MAX; mindis[S]=0; queue<int> q; q.push(S); inque[S]=1; while(!q.empty()){ int cur=q.front(); q.pop(); inque[cur]=0; for(int i=0;i<500;i++){ if(dis[cur][i]!=-1){ if(mindis[cur]+dis[cur][i]<mindis[i]){ mindis[i]=mindis[cur]+dis[cur][i]; mincost[i]=mincost[cur]+cost[cur][i]; pre[i]=cur; if(inque[i]==0){ q.push(i); inque[i]=1; } }else if(mindis[cur]+dis[cur][i]==mindis[i]){ if(mincost[cur]+cost[cur][i]<mincost[i]){ mincost[i]=mincost[cur]+cost[cur][i]; pre[i]=cur; if(inque[i]==0){ q.push(i); inque[i]=1; } } } } } } vector<int> vs; int t=D; while(true){ vs.push_back(t); if(t==S) break; t=pre[t]; } for(int i=vs.size()-1;i>=0;i--){ printf("%d ", vs[i]); } printf("%d %d", mindis[D], mincost[D]); return 0; }
标签:turn mem while href com problems for ack bre
原文地址:https://www.cnblogs.com/FEIIEF/p/12848362.html