
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e4 + 1;
int n, m, l, r, mid, mch, vst[N], flaG, ans;
struct Node {
int v, w, bj;
};
vector<Node>vec[N];
void dfs(int x, int color, int fa) {
vst[x] = color;
for (auto v : vec[x]) {
if (!v.bj && v.v != fa) {
if (!vst[v.v])dfs(v.v, 3 - color, x);
else if (vst[v.v] != 3 - color) {
flaG = 0;
return;
}
}
}
}
int Ran() {
flaG = 1;
for (int i = 1; i <= n; i++) {
if (vst[i]) {
dfs(i, 1, 0);
if (!flaG)return 0;
}
}
return 1;
}
bool check(int k) {
for (int i = 1; i <= n; i++) {
for (auto v : vec[i]) {
v.bj = 0;
if (v.w <= k) {
v.bj = 1;
}
}
}
bool x = Ran();
if (!x) {
return 1;
} else return 0;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
mch = max(mch, w);
vec[u].push_back({v, w});
vec[v].push_back({u, w});
}
// cout<<mch<<'\n';
l = 0, r = mch;
ans = mch;
while (l < r) { //二分枚举最大仇恨
mid = (l + r) >> 1;
// cout << l << ' ' << r << ' ' << mid << '\n';
if (check(mid)) {
r = mid;
ans = mid;
} else l = mid + 1;
}
cout << ans;
return 0;
}
炸了!!!!!!!!!!!!
满江红!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1