题目链接:http://poj.org/problem?id=1797
Time Limit: 3000MS Memory Limit: 30000K

Description

Background 
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight. 
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know. 

Problem 
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.

Input

The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.

Sample Input

1
3 3
1 2 3
1 3 4
2 3 5

Sample Output

Scenario #1:
4

Problem solving report:

Description: 求从1号到n号可以运输的最大重量。
Problem solving: 我们知道,求可以运输的最大重量,可以求从1号到n号可以运输的每条道路的最大重量,即求每条子路的最小载重量(类似于木桶原理),可以用最短路来做,也可以用最大生成树来做。

Accepted Code:

//最短路
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAXN = 1005;
const int inf = 0x3f3f3f3f;
bool vis[MAXN];
int mp[MAXN][MAXN], dis[MAXN], n, m;
int Dijkstra(int s) {
    memset(dis, 0, sizeof(dis));
    memset(vis, false, sizeof(vis));
    dis[s] = inf;
    for (int i = 0; i < n; i++) {
        int max_ = -inf, k = s;
        for (int j = 1; j <= n; j++)
            if (!vis[j] && dis[j] > max_)
                max_ = dis[k = j];
        vis[k] = true;
        for (int j = 1; j <= n; j++)
            if (mp[k][j] < inf)
                if (!vis[j] && dis[j] < min(dis[k], mp[k][j]))
                    dis[j] = min(dis[k], mp[k][j]);
    }
    return dis[n];
}
int main(){
    int t1, t2, t3, t;
    scanf("%d", &t);
    for (int kase = 1; kase <= t; kase++) {
        scanf("%d%d", &n, &m);
        memset(mp, 0, sizeof(mp));
        for (int i = 1; i <= m; i++) {
            scanf("%d%d%d", &t1, &t2, &t3);
            mp[t1][t2] = mp[t2][t1] = t3;
	    }
        printf("Scenario #%d:\n%d\n\n", kase, Dijkstra(1));
    }
    return 0;
}
//最大生成树
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1005;
struct edge {
    int u, v, w;
    bool operator < (const edge &s) const {
        return s.w < w;
    }
}e[MAXN * MAXN];
int f[MAXN], n, m;
int getf(int v) {
    if (f[v] != v)
        return f[v] = getf(f[v]);
    return v;
}
void merge(int u, int v) {
    int t1 = getf(u);
    int t2 = getf(v);
    if (t1 != t2)
        f[t2] = t1;
}
int main(){
    int t, i, ans;
    scanf("%d", &t);
    for (int kase = 1; kase <= t; kase++) {
        ans = 0;
        scanf("%d%d", &n, &m);
        for (i = 1; i <= n; i++)
            f[i] = i;
        for (i = 0; i < m; i++)
            scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
        sort(e, e + m);
        for (i = 0; i < m && getf(1) != getf(n); i++)
            merge(e[i].u, e[i].v);
        printf("Scenario #%d:\n%d\n\n", kase, e[i - 1].w);
    }
    return 0;
}