求每条道路的最大承载量
和上一道题差不多 就是松弛的规则从最大值变成了最小值
1 /* *********************************************** 2 Author :Sun Yuefeng 3 Created Time :2016/10/22 20:09:36 4 File Name :A.cpp 5 ************************************************ */ 6 7 #include<cstdio> 8 #include<iostream> 9 #include<algorithm> 10 #include<cmath> 11 #include<cstring> 12 #include<string> 13 #include<bitset> 14 #include<map> 15 #include<set> 16 #include<stack> 17 #include<vector> 18 #include<queue> 19 #include<list> 20 #define M(a,b) memset(a,b,sizeof(a)) 21 using namespace std; 22 typedef long long ll; 23 const int inf=0x3f3f3f3f; 24 const int maxn=1e3+10; 25 const int mod=1e7+7; 26 int dx[8]= {0,0,1,-1,1,-1,1,-1}; 27 int dy[8]= {1,-1,0,0,-1,1,1,-1}; 28 29 int n,m; 30 int way[maxn][maxn]; 31 int dis[maxn]; 32 bool vis[maxn]; 33 34 void dijkstra(){ 35 for(int i=1;i<=n;i++){ 36 dis[i]=way[i][1]; 37 vis[i]=false; 38 } 39 for(int i=1;i<=n;i++){ 40 int k=-1; 41 int mi=-1; 42 for(int j=1;j<=n;j++){ 43 if(!vis[j]&&dis[j]>mi){ 44 mi=dis[j]; 45 k=j; 46 } 47 } 48 vis[k]=true; 49 for(int j=1;j<=n;j++){ 50 if(dis[j]<min(dis[k],way[j][k])&&!vis[j]) 51 dis[j]=min(dis[k],way[j][k]); 52 } 53 } 54 printf("%d ",dis[n]); 55 } 56 57 int main() 58 { 59 //freopen("in.txt","r",stdin); 60 //freopen("out.txt","w",stdout); 61 int T,_case=1; 62 scanf("%d",&T); 63 while(T--){ 64 M(way,-1); 65 printf("Scenario #%d: ",_case++); 66 int u,v,w; 67 scanf("%d%d",&n,&m); 68 for(int i=0;i<m;i++){ 69 scanf("%d%d%d",&u,&v,&w); 70 way[u][v]=way[v][u]=w; 71 } 72 dijkstra(); 73 } 74 return 0; 75 }