Test instructions: A group of knights to sit on a round table, some of them hate each other, so can not be next to each other, asked to work out a table can not be a person, each meeting table must be odd number of people, a person can not meet
Solutions: You can first build a fill map, to meet the problem conditions we just find all the odd circle (odd number of points of the ring), the point-the double-link component, for each individual point-the double connected component, if it must be a singular circle, then can not be stained by a binary graph, it is possible to verify the conclusion by drawing, So we dye all the dots in the odd circle and end up with no colored dots, because there may be multiple staining points, so it's not possible to add points directly each time.
Pit point: Can not use stl,tle a lot of hair, and finally all the vector,map are replaced with an array on the past, can not use vector map, then use my favorite chain forward to the Star bar =
#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<vector>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#defineFi first#defineSe Second#defineMP Make_pair#definePB Push_back#definePII pair<int,int>#defineC 0.5772156649#definePi ACOs (-1.0)#definell Long Long#defineMoD 1000000007#defineLS l,m,rt<<1#defineRS M+1,r,rt<<1|1using namespacestd;using namespace__gnu_cxx;Const Doubleg=10.0, eps=1e-7;Const intn= ++Ten, maxn=1000000+Ten, inf=0x3f3f3f;structedge{intTo,next;} E[MAXN];intBcc[n];intIndex,num;intCnt,head[n];intDfn[n],low[n];intBccno[n];structewedge{int from, to;}; Stack<ewedge>s;BOOLMa[n][n];int inch[n],ok[n];intColor[n];BOOLnotsub;voidAddintXinty) {e[cnt].to=y; E[CNT]. Next=Head[x]; HEAD[X]=cnt++; E[cnt].to=x; E[CNT]. Next=Head[y]; Head[y]=cnt++;}voidDfsintUintFintp) { if(notsub)return ; Color[u]=p; intC=3-p; for(intI=head[u];~i;i=E[i]. Next) {intx=e[i].to; if(Ok[x]) {if(!color[x]) DFS (X,U,C); Else { if(color[x]!=c) notsub=1; } } }}voidTarjan (intUintf) {Low[u]=dfn[u]=++index; for(intI=head[u];~i;i=E[i]. Next) {intx=e[i].to; Ewedge e=(Ewedge) {u,x}; if(x==f)Continue; if(!Dfn[x]) {S.push (e); Tarjan (X,u); Low[u]=min (low[u],low[x]); if(low[x]>=Dfn[u]) { intres=0; Num++; memset (OK,0,sizeofOK); intBe=0; for(;;) {Ewedge P=s.top (); S.pop (); if(Bccno[p. from]!=num) {Bcc[res++]=p. from; be=p. from; Bccno[p. from]=num; Ok[p. from]=1; } if(bccno[p.to]!=num) {Bcc[res++]=p.to; be=p.to; Bccno[p.to]=num; Ok[p.to]=1; } if(p. from==e. from&&P.TO==E.TO) Break; } //Judging is not a two-point chart for(intI=0; i<res;i++) Color[bcc[i]]=0; Notsub=0; DFS (BE,-1,1); if(notsub) { for(intI=0; i<res;i++) inch[bcc[i]]=1; } /*cout<<notsub<< "--------"; for (int j=0;j<bcc.size (); j + +) cout<<bcc[j]<< ""; cout<<endl;*/ } } Else { if(Dfn[x]<dfn[u]) low[u]=min (low[u],dfn[x]); } }}voidInitintN) {memset (head,-1,sizeofhead); Memset (MA,0,sizeofMA); for(intI=1; i<=n;i++) {Bccno[i]=dfn[i]=low[i]=inch[i]=0; } while(!s.empty ()) S.pop (); Index=num=cnt=0;}intMain () {intn,m; while(~SCANF ("%d%d",&n,&m)) {if(!n&&!m) Break; Init (n); while(m--) { intb; scanf ("%d%d",&a,&b); MA[A][B]=ma[b][a]=1; } for(intI=1; i<=n;i++) for(intj=i+1; j<=n;j++) if(!Ma[i][j]) Add (I,J); for(intI=1; i<=n;i++) if(!Dfn[i]) Tarjan (i,-1); intans=0; for(intI=1; i<=n;i++) if(inch[i]) ans++; printf ("%d\n", N-ans); } return 0;}/************************/View Code
poj2942 Point-Double Unicom + two-part graph dyeing