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