标签:mit out ++ time bsp eof class port col
#include<map> #include<queue> #include<time.h> #include<limits.h> #include<cmath> #include<ostream> #include<iterator> #include<set> #include<stack> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep_1(i,m,n) for(int i=m;i<=n;i++) #define mem(st) memset(st,0,sizeof st) int read() { int res=0,ch,flag=0; if((ch=getchar())==‘-‘) //判断正负 flag=1; else if(ch>=‘0‘&&ch<=‘9‘) //得到完整的数 res=ch-‘0‘; while((ch=getchar())>=‘0‘&&ch<=‘9‘) res=res*10+ch-‘0‘; return flag?-res:res; } typedef long long ll; typedef pair<int,int> pii; typedef unsigned long long ull; typedef pair<double,double> pdd; const int inf = 0x3f3f3f3f; const int N=210; int dist[N][N]; int ans[N][N]; int n,m; int res[N]; int main() { cin>>n>>m; for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(i!=j) dist[i][j]=dist[j][i]=2e6; for(int i=1; i<=m; i++) { int a,b,c; cin>>a>>b>>c; dist[a][b]=dist[b][a]=c; } for(int k=1; k<=n; k++) for(int i=1; i<=n; i++) if(i!=k) for(int j=1; j<=n; j++) if(i!=j&&j!=k) { if(dist[i][j]>dist[i][k]+dist[k][j]) dist[i][j]=dist[i][k]+dist[k][j],ans[i][j]=k; else if(dist[i][j]==dist[i][k]+dist[k][j]) ans[i][j]=-1; } for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(ans[i][j]!=-1) res[ans[i][j]]=1; int flag=0; for(int i=1; i<=n; i++) if(res[i]==1) cout<<i<<" ",flag=1; if(flag==0) cout<<"No important cities."<<endl; return 0; }
luogu P1841 [JSOI2007]重要的城市 dp+Floyd
标签:mit out ++ time bsp eof class port col
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/13041033.html