NOIP2010 Imprisoned criminals

Source: Internet
Author: User

Topic Link: Portal

Topic Ideas: And check the high-level application (similar to the food chain that problem), mainly to maintain two sets (prison inmates of the relationship), the same set of friends, or enemies, if the enemy in the same prison,

The minimum maximum conflict value is calculated.

#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<cstring>#include<stack>#include<cctype>#include<queue>#include<string>#include<vector>#include<Set>#include<map>#include<climits>#defineLson Root<<1,l,mid#defineRson Root<<1|1,mid+1,r#defineFi first#defineSe Second#defineSEG int Root,int L,int r#definePing (x, y) ((x-y) * (x-y))#defineMST (x, y) memset (x,y,sizeof (x))#defineMCP (x, y) memcpy (x,y,sizeof (y))#defineMin (x, y) (x<y?x:y)#defineMax (x, y) (x>y?x:y)using namespacestd;#defineGamma 0.5772156649015328606065120#defineMOD 100000007#defineINF 0x3f3f3f3f#defineN 100005#defineMAXN 10001000typedefLong LongLl;typedef pair<int,int>PII;structnode{intx, y; intv; BOOL operator< (ConstNode &a)Const{        returnV>A.V; }}node[n];intfp[n<<1];intFINDP (intx) {returnfp[x]==x?x:fp[x]=FINDP (fp[x]);}intMain () {intI,x,y,m,n; scanf ("%d%d",&n,&m);  for(i=0; i<m;++i) {scanf ("%d%d%d",&node[i].x,&node[i].y,&node[i].v); }     for(i=0;i<=n<<1; ++i) fp[i]=i; Sort (Node,node+M);///Greedy thought    intans=0;  for(i=0; i<m;++i) {x=node[i].x; Y=node[i].y; intxx=FINDP (x); intyy=FINDP (y); if(xx==yy) {ans=node[i].v;  Break; } Fp[xx]=FINDP (Y+n);///the enemy of X and Y must be in the same prison.FP[YY]=FINDP (X+n);///the same as Y and X enemies must be in a prison} printf ("%d\n", ans); return 0;}

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.