From 3d1c87a825582f827e83b76903e7982ba4b48285 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 27 Apr 2016 11:35:56 +0800 Subject: [PATCH] Create 1403.cpp --- TYVJ/1403.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 TYVJ/1403.cpp diff --git a/TYVJ/1403.cpp b/TYVJ/1403.cpp new file mode 100644 index 0000000..840b165 --- /dev/null +++ b/TYVJ/1403.cpp @@ -0,0 +1,40 @@ +#include +#include +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<