mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 1403.cpp
This commit is contained in:
parent
821d7fc80e
commit
3d1c87a825
40
TYVJ/1403.cpp
Normal file
40
TYVJ/1403.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#include <algorithm>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int n,m,f[40001],x,y;
|
||||
struct data
|
||||
{
|
||||
int a,b,c;
|
||||
}e[100001];
|
||||
int gz(const data &a,const data &b)
|
||||
{
|
||||
if(a.c>b.c)return 1;
|
||||
else return 0;
|
||||
}
|
||||
int find(int x)
|
||||
{
|
||||
return f[x]==x?x:f[x]=find(f[x]);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
cin>>n>>m;
|
||||
for(int i=1;i<=m;i++)
|
||||
cin>>e[i].a>>e[i].b>>e[i].c;
|
||||
for(int i=1;i<=n*2;i++)
|
||||
f[i]=i;
|
||||
sort(e+1,e+m+1,gz);
|
||||
for(int i=1;i<=m;i++)
|
||||
{
|
||||
x=find(e[i].a);
|
||||
y=find(e[i].b);
|
||||
if(x==y)
|
||||
{
|
||||
cout<<e[i].c;
|
||||
return 0;
|
||||
}
|
||||
f[y] = find(e[i].a + n);
|
||||
f[x] = find(e[i].b + n);
|
||||
}
|
||||
cout<<0;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user