解题思路
本题用并查集的方法
AC代码
#include <bits/stdc++.h>
using namespace std;
int f[55555];
struct S
{int a,b,c;friend inline bool operator<(S a, S b){return a.c>b.c;}
} d[100000];int find(int x) {return f[x]==x? x:(f[x]=find(f[x]));
}int main() {int n, m;cin >> n >> m;for (int i(0);i<m;i++)cin>>d[i].a>>d[i].b>>d[i].c;sort(d,d+m);for (int i(0);i<2*n;i++)f[i] = i;for (int i(0);i<m;i++){int fx(find(d[i].a)),fy(find(d[i].b));if (fx==fy){cout <<d[i].c<<endl;return 0;}f[fx] = find(d[i].b + n);f[fy] = find(d[i].a + n);}cout << 0 << endl;return 0;
}