标签:
题目链接:http://poj.org/problem?id=1797
Description
Input
Output
Sample Input
1 3 3 1 2 3 1 3 4 2 3 5
Sample Output
Scenario #1: 4
题目大意:一个人要从1号路口送货到n号路口,但是每条路都有载重限制,问这个人最多能送多重的货物
解题思路:最短路,将判断条件改为每条路的负重即可
1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 #include<iomanip> 6 #include<map> 7 8 using namespace std; 9 10 int street[1005][1005], dis[1005]; 11 bool flag[1005]; 12 13 int main(){ 14 ios::sync_with_stdio( false ); 15 16 int T, n, m, x, y, temp; 17 cin >> T; 18 for( int t = 1; t <= T; t++ ){ 19 cin >> n >> m; 20 memset( street, -1, sizeof( street ) ); 21 memset( flag, true, sizeof( flag ) ); 22 for( int i = 0; i < m; i++ ){ 23 cin >> x >> y >> temp; 24 street[x][y] = street[y][x] = temp; 25 } 26 for( int i = 2; i <= n; i++ ){ 27 dis[i] = street[1][i]; 28 } 29 30 for( int k = 1; k < n; k++ ){ 31 int maxx = -1, maxi = 1; 32 for( int i = 2; i <= n; i++ ){ 33 if( flag[i] && dis[i] > maxx ){ 34 maxx = dis[i]; 35 maxi = i; 36 } 37 } 38 39 flag[maxi] = false; 40 41 for( int i = 2; i <= n; i++ ){ 42 if( flag[i] && dis[i] < min( dis[maxi], street[maxi][i] ) ){ 43 dis[i] = min( dis[maxi], street[maxi][i] ); 44 } 45 } 46 } 47 48 cout << "Scenario #" << t << ":" << endl << dis[n] << endl << endl; 49 } 50 51 return 0; 52 }
POJ-1797 Heavy Transportation( 最短路 )
标签:
原文地址:http://www.cnblogs.com/hollowstory/p/5584138.html