"Bzoj4668-" and "the Cold War"

Source: Internet
Author: User

"The main topic"

Given n military plants and M operations, the operation is divided into two categories: 0 u V, this operation of the Soviet Union will be built to connect the U military plant and the railway of the V plant, note that the railways are two-way; 1 U V, Reddington need to know the U military Plant and the USS V plant as early as the entry of the first railway lines Will Unicom, if this operation is not connected, then output 0. "Thinking" began to see the past state of the first reaction can be sustained, and immediately feel stupid. The common and check set, each time also to record the next t[u],t[u] that the U military factory and its father when the connection. So for u and V, if they are connected, it is U->lca (u,v)->v The maximum value of t[u] on this path. "Error Point" I actually started writing u->fa[u]->v ... In fact, LCA is OK, LCA is not necessarily the ultimate father.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Const intmaxn=500000+ -;7 intU[MAXN],H[MAXN],T[MAXN];8 intDEP[MAXN];9 intTim;Ten intans=0, preans=0, n,m; One  A intFindintx) - { -      while(X!=u[x]) x=U[x]; the     returnx; - } -  - voidGETDEP (intx) + { -     if(u[x]==x) +     { Adep[x]=0; at         return; -     } -     ElseGETDEP (u[x]); -dep[x]=dep[u[x]]+1; - } -  in intAskintXinty) - { to     intret=-1; + GETDEP (x); - getdep (y); the     if(dep[x]<Dep[y]) swap (x, y); *      while(dep[x]>Dep[y]) $     {Panax Notoginsengret=Max (ret,t[x]); -x=U[x]; the     } +      while(x!=y) A     { theret=Max (Ret,max (t[x],t[y)); +x=U[x]; -y=U[y]; $     } $     returnret; - } -  the voidMintime (intAintb) - {Wuyi     intFa=find (a), fb=find (b); the     if(FA!=FB) ans=0; -         Elseans=Ask (A, b); Wuprintf"%d\n", ans); -preans=ans; About } $  - voidUnion_set (intAintb) - { -++Tim; A     intFa=find (a), fb=find (b); +     if(fa!=FB) the     {  -         if(h[fa]>H[FB]) $         { thet[fb]=Tim; theu[fb]=FA; the         } the         Else -         { int[fa]=Tim; theu[fa]=FB; the             if(H[FA]==H[FB]) + +H[FB]; About         } the     } the } the  + voidInit () - { thememset (DEP,0,sizeof(DEP));Bayi      for(intI=1; i<=n;i++) theu[i]=i,h[i]=1; the }  -  - voidSolve () the { thescanf"%d%d",&n,&m); thetim=0; the init (); -      for(intI=0; i<m;i++) the     { the         intop,a,b; thescanf"%d%d%d",&op,&a,&b);94a^=Preans; theb^=Preans; the         if(!op) Union_set (A, b); the             ElseMintime (A, b);98     } About }  - 101 intMain ()102 {103 solve ();104     return 0; the}

"Bzoj4668-" and "the Cold War"

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.