Today, the teacher is not, do not test, Kai Sen, to brush the problem, but tonsillitis that is my own death
Title: In a city, there is such a lump of criminals, they may have a grudge value between each other, the city has two prisons, you can place them, once the resentment value of the two people meet, will cause the corresponding impact, you calculate the minimum impact value
Today our body is not good, not easy too much nonsense, we directly began, we have to deposit the relationship can be regarded as 2.1 weight margin, then we are based on the W sort side, like Kruskal greedy edge can.
#include <algorithm>#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>using namespaceStd;typedefLong Longll;structedge{inta,b,w;}; Const intSize = 2e4 +4;Const intSize = 1e5 +5;intFather[size <<1];edge data[size];BOOLCMP (Edge,edge);intGetfather (int);intMain () {intN,m,ans =0; scanf ("%d%d",&n,&m); for(inti =0; i < m; ++i) scanf ("%d%d%d",&data[i].a,&data[i].b,&DATA[I].W); Sort (Data,data+m,cmp); for(inti = n <<1I --i) father[i]=i; for(inti =0; i < m; ++i) { intx =Getfather (DATA[I].A); inty =Getfather (DATA[I].B); if(x = =y) {ans=DATA[I].W; Break; } Father[x]= Getfather (data[i].b +N); Father[y]= Getfather (data[i].a +N); } printf ("%d\n", ans); return 0;} BOOLcmp (Edge A,edge b) {returnA.W >B.W;}intGetfather (intx) { if(Father[x] = =x)returnx; returnFATHER[X] =Getfather (father[x]);}
NOIP2010 Imprisoned criminals