OJ-Problems-Source/RQNOJ/600.cpp
2016-04-27 16:17:02 +08:00

60 lines
999 B
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXM 100000
#define MAXN 20000
struct ppk
{
    int a,b,c;
};
bool cmp(const ppk& a,const ppk& b)
{
    return a.c>b.c;
}
int f[MAXN*2];
ppk X[MAXM];
int get(int x)
{
    if(x==f[x]) return x;
    else
    {
        f[x]=get(f[x]);
        return f[x];
    }
}
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n*2;i++)
    {
        f[i]=i;
    }
    for(int i=0;i<m;i++)
    {
        scanf("%d %d %d",&X[i].a,&X[i].b,&X[i].c);
    }
    sort(X,X+m,cmp);
    for(int s=0;s<m;s++)
    {
        int x=get(X[s].a);
        int y=get(X[s].b);
        if(x==y)
        {
            printf("%d\n",X[s].c);
            return 0;
        }
        int w=get(X[s].a+n);
        int t=get(X[s].b+n);
        f[x]=t;
        f[y]=w;
}
    printf("0\n");
    return 0;
}