标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 13588 | Accepted: 5259 |
Description
Input
Output
Sample Input
3 3 1 2 23 2 3 1000 1 3 43
Sample Output
43
Hint
Source
#include <cstdio> #include <cstring> #define N 2001 const int INF = 0x3f3f3f3f; int dis[N], vis[N], map[N][N]; int n, m, maxlen; void Prime() { memset(vis, 0, sizeof(vis)); for(int i = 1; i <= n; i++) dis[i] = map[1][i]; vis[1] = 1; for(int i = 1; i < n; i++){ int temp, min = INF; for(int j = 1; j <= n; j++) if(!vis[j] && dis[j] < min){ temp = j; min = dis[j]; } if(min==INF) return; vis[temp] = 1; if(dis[temp] > maxlen) maxlen = dis[temp]; for(int j = 1; j <= n; j++) if(!vis[j] && dis[j] > map[temp][j]) dis[j] = map[temp][j]; } } int main() { while(scanf("%d%d", &n, &m) != EOF) { maxlen = -1; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) map[i][j] = -1; for(int i = 0; i < m; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); if(map[a][b] == -1 || map[a][b] > c) map[a][b] = map[b][a]=c; } for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) if(map[i][j] == -1) map[i][j] = INF; Prime(); printf("%d\n", maxlen); } return 0; }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/5087169.html