标签:mes turn namespace alt std for void pac 传送门
#include<cstdio> #include<algorithm> using namespace std; const int maxn = 20005; int fa[maxn],q[maxn]; int n,m; struct abc { int a,b,c; } p[200005]; int cmp(abc x,abc y) { return x.c > y.c; } int getfather(int x) { if(x == fa[x])return x; fa[x] = getfather(fa[x]); return fa[x]; } void add(int x,int y){ x = getfather(x); y = getfather(y); fa[x] = y; } int main() { scanf("%d%d",&n,&m); for(int i = 1;i <= n;i++) fa[i] = i; for(int i = 1; i <= m; i++) scanf("%d%d%d",&p[i].a,&p[i].b,&p[i].c); sort(p+1,p+m+1,cmp); for(int i = 1; i <= m; i++) { if(getfather(p[i].a) == getfather(p[i].b)){ printf("%d",p[i].c); return 0; } if(!q[p[i].a])q[p[i].a] = p[i].b; else add(q[p[i].a],p[i].b); if(!q[p[i].b])q[p[i].b] = p[i].a; else add(q[p[i].b],p[i].a); } printf("0"); return 0; }
标签:mes turn namespace alt std for void pac 传送门
原文地址:https://www.cnblogs.com/mogeko/p/9901944.html