标签:out stream cst pre lib clu turn pac print
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> using namespace std; struct uio{ int from,to,que; }edge[1001]; int road[1001],n,m; int main() { cin>>n>>m; for(int i=1;i<=m;i++) cin>>edge[i].from>>edge[i].to>>edge[i].que; memset(road,0x7F,sizeof road); road[1]=0; for(int i=1;i<=n-1;i++) { int check=0; for(int j=1;j<=m;j++) if(road[edge[j].to]>road[edge[j].from]+edge[j].que) { road[edge[j].to]=road[edge[j].from]+edge[j].que; check=1; } if(check==0) break; } for(int i=1;i<=m;i++) if(road[edge[i].to]>road[edge[i].from]+edge[i].que) { printf("此图含有负权回路"); return 0; } for(int i=1;i<=n;i++) cout<<road[i]<<" "; cout<<endl; return 0; }
标签:out stream cst pre lib clu turn pac print
原文地址:https://www.cnblogs.com/water-radish/p/9280684.html