Luo Gu P1396

P1396

Portal

Pull some digression

I just saw this really say when the problem is really silly fufu of .....

Roughly 题意

S t come to find out from the maximum value of minimum congestion degrees ..

Thinking

He said maximum minimum possible there will be half a dalao start.

I think this kind of Konjac can only play some kruskal maintain the look of life ...

That is that : because kruskal each side when the first row of the right side of the order, at the same time when the collection area s and t zone until.

The maximum value of the path is the right side of the last edge of the current connection.

For a start it is sorted by size kruskal right side, and it shows that the maximum value of each must be the smallest of the maximum value.

Then there is no then the ..

code

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iomanip>
#include <cstdlib>
#include <iostream>
#include <algorithm>

#define N 20010
#define M 10010

using namespace std;
int fath[N], n, m, s, t;
struct node {
    int x, y, dis;
}e[N];

int read() {
    int s = 0, f = 0; char ch = getchar();
    while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
    while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
    return f ? -s : s;
}

bool cmp(node a, node b) {
    return a.dis < b.dis;
}

int father(int x) {
    if (x != fath[x]) fath[x] = father(fath[x]);
    return fath[x];
}

int main() {
    n = read(), m = read(), s = read(), t = read();
    for (int i = 1, u, v, w; i <= m; i++) {
        u = read(), v = read(), w = read();
        e[i].x = u, e[i].y = v, e[i].dis = w;
    }
    for (int i = 1; i <= n; i++) fath[i] = i;
    sort(e + 1, e + m + 1, cmp);
    int ans;
    for (int i = 1; i <= m; i++) {
        int fx = father(e[i].x), fy = father(e[i].y);
        if (fx != fy) {
            fath[fx] = fy;
            ans = e[i].dis;
        }
        if (father(s) == father(t)) break;
    }
    cout << ans;
}

Guess you like

Origin www.cnblogs.com/zzz-hhh/p/11612436.html