标签:des style blog http color strong
MPI Maelstrom
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 5044 | Accepted: 3089 |
Description
Input
Output
Sample Input
5 50 30 5 100 20 50 10 x x 10
Sample Output
35
Source
解题:dijkstra算法,求1到所有其他点的最短中最大的那个值。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <algorithm> 8 #include <cmath> 9 #define LL long long 10 using namespace std; 11 const int INF = INT_MAX>>2; 12 int table[110][110]; 13 int d[110]; 14 bool vis[110]; 15 int dij(int n){ 16 int i,j,theMin,index,ans = 0; 17 memset(vis,false,sizeof(vis)); 18 for(i = 0; i <= n; i++){ 19 d[i] = INF; 20 } 21 d[1] = 0; 22 for(i = 1; i <= n; i++){ 23 theMin = INT_MAX; 24 for(j = 1; j <= n; j++){ 25 if(!vis[j] && d[j] < theMin) theMin = d[index = j]; 26 } 27 vis[index] = true; 28 for(j = 1; j <= n; j++){ 29 if(!vis[j] && d[j] > d[index] + table[index][j]){ 30 d[j] = d[index]+table[index][j]; 31 } 32 } 33 } 34 for(i = 2; i <= n; i++){ 35 ans = max(ans,d[i]); 36 } 37 return ans; 38 } 39 int main(){ 40 int i,j,n,temp; 41 char ch; 42 while(~scanf("%d",&n)){ 43 memset(table,0,sizeof(table)); 44 for(i = 2; i <= n; i++){ 45 for(j = 1; j < i; j++){ 46 if(scanf("%d",&temp)){ 47 table[j][i] = table[i][j] = temp; 48 }else{ 49 table[i][j] = table[j][i] = INF; 50 scanf("%c",&ch); 51 } 52 } 53 } 54 printf("%d\n",dij(n)); 55 } 56 return 0; 57 }
POJ 1502 MPI Maelstrom,布布扣,bubuko.com
标签:des style blog http color strong
原文地址:http://www.cnblogs.com/crackpotisback/p/3833619.html