题目

传送门

题解

后面补

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 20009;
const int M = 100009;
int n, m;
struct Edge {
int s, t, d;
bool operator < (const Edge &a) const {
return d > a.d;
}
}e[M];
int f[2*N];
int find(int x) {
return f[x] == x ? f[x] : f[x] = find(f[x]);
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &e[i].s, &e[i].t, &e[i].d);
}
sort(e + 1, e + m + 1);
for (int i = 1; i <= n; i++) {
f[i] = i;
f[i + n] = i + n;
}
for (int i = 1; i <= m; i++) {
int fs = find(e[i].s), ft = find(e[i].t);
if (fs == ft) {
printf("%d\n", e[i].d);
return 0;
}
f[fs] = find(e[i].t + n);
f[ft] = find(e[i].s + n);
}
printf("0\n");
return 0;
}