NOIP2010 Imprisoned criminals

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.