Bzoj 1997: [Hnoi2010]planar

Source: Internet
Author: User

1#include <cstdio>2#include <cstring>3#include <iostream>4 #defineM 200055 #defineN 20056 using namespacestd;7 intt,n,m,head[n],next[ -*m],u[ -*M],x[m],y[m],pos[n],cnt,tot,c[n],dfn[n],low[n],f[n],tim,t,z[m],sum,shu[m];8 voidTarjan (intx)9 {Tenf[x]=1; z[++t]=x; Onelow[x]=dfn[x]=++Tim; A      for(intI=head[x];i;i=Next[i]) -         if(!Dfn[u[i]]) -Tarjan (U[i]), low[x]=min (Low[x],low[u[i]]); the         Else if(F[u[i]]) -low[x]=min (Low[x],dfn[u[i]]); -     intnow=-1; -     if(low[x]==Dfn[x]) +     { -sum++; +          while(now!=x) A         { atnow=z[t--];f[now]=0; -shu[now]=sum; -         } -     } - } - voidJiaintA1,intA2) in { -cnt++; tonext[cnt]=HEAD[A1]; +head[a1]=CNT; -u[cnt]=A2; the } * BOOLPan () $ {Panax Notoginseng      for(intI=1; i<=m;i++) -       if(shu[2*i]==shu[2*i-1]) the         return 0; +     return 1; A } the intMain () + { -scanf"%d",&T); $      for(; T t--) $       { -scanf"%d%d",&n,&m); -          for(intI=1; i<=m;i++) thescanf"%d%d",&x[i],&y[i]); -Memset (Head,0,sizeof(head));Wuyisum=cnt=tim=0; thememset (DFN,0,sizeof(DFN)); -memset (Low,0,sizeof(Low)); Wu          for(intI=1; i<=n;i++) -scanf"%d",&c[i]); About         if(m>3*n-6) $           { -printf"no\n"); -             Continue; -           } Atot=0; +          for(intI=1; i<=n;i++) thepos[c[i]]=i; -          for(intI=1; i<=m;i++) $           { thex[i]=Pos[x[i]]; they[i]=Pos[y[i]]; the             if(x[i]>Y[i]) the swap (x[i],y[i]); -             if(y[i]-x[i]==1|| (y[i]==n&&x[i]==1)) in               Continue; thetot++; thex[tot]=X[i]; Abouty[tot]=Y[i]; the           } them=tot; the          for(intI=1; i<=m;i++) +            for(intj=i+1; j<=m;j++) -             if((X[i]<x[j]&&x[j]<y[i]&&y[i]<y[j]) | | (x[j]<x[i]&&x[i]<y[j]&&y[j]<Y[i])) the               {BayiJia (i*2, j*2-1); theJia (j*2-1, i*2); theJia (i*2-1, j*2); -Jia (j*2, i*2-1); -               } the          for(intI=1; i<=2*m;i++) the           if(!Dfn[i]) the Tarjan (i); the         if(Pan ()) -printf"yes\n"); the         Else theprintf"no\n"); the       }94     return 0; the}

Plan in the ring at most there are n-3, outside the ring at most there are n-3, ring on the N, so more than 3*n-6 edge must not be a plan, and then all the edges in accordance with Hamilton re-numbering, to determine whether the intersection, the words must be an outside, a line,

This becomes a 2-set problem, run with Tarjin.

Bzoj 1997: [Hnoi2010]planar

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.