标签:
题目链接:http://poj.org/problem?id=1797
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 30840 | Accepted: 8191 |
Description
Input
Output
Sample Input
1 3 3 1 2 3 1 3 4 2 3 5
Sample Output
Scenario #1: 4
题目大意:样例个数T,给定N个点,及M条边的最大负载,求顶点1到N的最大流。
// 1.给定一个双向可达的有向图,求出1->n之间的所有可达路径,每条路径中的最小边的最大值。
AC代码:
1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 int visit[1010]; 6 int dis[1010]; 7 int p[1010][1010]; 8 int n; 9 int dijkstra() 10 { 11 int i,j,pos,minn; 12 for (i = 1; i <= n; i ++) 13 { 14 dis[i] = p[1][i]; 15 visit[i] = 0; 16 } 17 dis[1] = 0; 18 visit[1] = 1; 19 20 for (i = 1; i <= n; i ++) 21 { 22 minn = 0; 23 for (j = 1; j <= n; j ++) 24 { 25 if (!visit[j] && dis[j] > minn) 26 { 27 minn = dis[j]; 28 pos = j; 29 } 30 } 31 visit[pos] = 1; 32 for (j = 1; j <= n; j ++) 33 { 34 if(!visit[j] && dis[j] < min(dis[pos],p[pos][j])) 35 dis[j] = min(dis[pos],p[pos][j]); 36 } 37 } 38 return dis[n]; 39 } 40 int main() 41 { 42 int t,m,x,y,z,i,j,f = 1; 43 scanf("%d",&t); 44 while (t --) 45 { 46 scanf("%d%d",&n,&m); 47 for (i = 1; i <= n; i ++) 48 for (j = 1; j <= n; j ++) 49 p[i][j] = 0; 50 for (i = 0; i < m; i ++) 51 { 52 scanf("%d%d%d",&x,&y,&z); 53 p[x][y] = p[y][x] = z; 54 } 55 printf("Scenario #%d:\n",f ++); 56 printf("%d\n\n",dijkstra()); //注意格式 57 } 58 }
标签:
原文地址:http://www.cnblogs.com/yoke/p/5862517.html