P1396
いくつかの脱線を引っ張ります
私はただ、問題は本当に愚かなフフあるときに、これは本当に言いました.....
大体题意
S tは最小混雑度の最大値から見つけるために来..
考え
彼は、最大可能な最小の半分dalao開始があるだろうと述べました。
私は、こんにゃく、この種のが唯一の生活の外観を維持するいくつかのクラスカルを再生することができると思います...
つまり、その:クラスカルので、各側面と同時にオーダーの右辺の最初の行するまで収集領域SとTゾーン。
パスの最大値は、現在の接続の最後のエッジの右側です。
開始のためには、サイズクラスカル右側でソートし、各最大値が最大値の最小でなければならないことを示しています。
そして、何もそこではありません。..
コード
#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;
}