DescriptionThe Little Prince small c often abuse vegetables, especially in the graph theory, often the small d abuse very miserable very miserable. This is not, small C let small d to find a maximum independent set of the graph, popularly speaking is: in the non-map to select a number of points, these points are not connected to each other, and so that the points taken out as much as possible. Small D Although the graph theory is very weak, but also know that the largest independent set of the graph is NPC, but small c very benevolent to give a very characteristic diagram: any one side of the graph belongs to and only a simple ring, there is no heavy edge and self-loop. Small c says it will compare the water. Small D think this topic is very interesting, you have to give, I believe you can solve it. InputThe first line, two numbers n, m, represents the number of points and sides of a graph. The second ~m+1 line, each row of two numbers x, Y, indicates that there is a non-forward edge between X and Y. Outputoutputs the maximum independent set of this graph. DFS disconnects one edge on each ring at a time, and all points on the ring except the root of the ring form a chain F0/F1 indicates that a point is not selected/not enforced when the maximum independent set in the DFS subtree G0/G1 represents a point not selected/does not make a mandatory requirement, But at the bottom of the chain where this point is forced is not selected when the maximum independent set transfer in a DFS subtree is similar to a tree DP
#include <cstdio>Const intn=51000, r=1500000;Charbuf[r+4],*ptr=buf-1;intn,m,ans=0;intet[121000],enx[121000],e0[n],ep=2;inted[n],stk[n],stp=0, bm[n],tp[n],dep[n];intF0[n],f1[n],g0[n],g1[n];inlineint_int () {intx=0, c=*++ptr; while(c< -) c=*++ptr; while(c> -) x=x*Ten+c- -, c=*++ptr; returnx;} InlinevoidMAXS (int&a,intb) {if(a<b) a=b;}BOOLRt[n];voidDFS1 (intW) {Ed[w]=1; stk[++stp]=W; for(intI=e0[w],u;i;i=enx[i])if(u=Et[i]) { if(!Ed[u]) {Et[i^1]=0; Dep[u]=dep[w]+1; DFS1 (U); }Else{Et[i]=et[i^1]=0; while(dep[stk[stp]]>Dep[u]) { intx=stk[stp--]; BM[X]=w;tp[x]=u; } } } if(stk[stp]==w)--STP;}voidDFS2 (intW) {F1[w]=1; if(W!=bm[w]) g1[w]=1; for(intI=e0[w],u;i;i=enx[i])if(u=Et[i]) {DFS2 (U); if(bm[u]!=Bm[w]) { if(tp[u]!=w) g0[w]+=f1[u],g1[w]+=F0[u]; Elseg0[w]+=f1[u],g1[w]+=G0[u]; }Elseg0[w]+=g1[u],g1[w]+=G0[u]; if(tp[u]!=w) f0[w]+=f1[u],f1[w]+=F0[u]; Elsef0[w]+=f1[u],f1[w]+=G0[u]; } maxs (F1[w],f0[w]); Maxs (G1[w],g0[w]);}intMain () {fread (buf,1, R,stdin); N=_int (); m=_int (); while(m--){ intA=_int (), b=_int (); ET[EP]=b;enx[ep]=e0[a];e0[a]=ep++; ET[EP]=a;enx[ep]=e0[b];e0[b]=ep++; } DFS1 (1);d FS2 (1); printf ("%d\n", f1[1]); return 0;}
bzoj4316: A separate set of small C