The random method is really good. O (∩_∩) o~
At the earliest, Miaom raised a strange thing:
Determine if there is an odd number of 0/1/2 in a sequence of numbers
Assign a random weight to each number, XOR, and for the case of 2, use a (possibly linear-based) method
And then I started to blind BB: Can I assign some random rights on the edge or the point, and do some determinant problems of graph theory
(*^▽^*) to determine the non-map unicom
First consider building a spanning tree, and any operations that disrupt connectivity need to destroy the edges of the tree.
There must be a subtrees tree falling down to make the diagram go away.
and the condition of the subtree falling is that its root is disconnected from the side of the Root's father, and the non-tree edges of the connecting subtree and the outside point of the tree are disconnected
It's a very good nature, and it can be used to make things happen.
A random weight is assigned to the edges outside the tree, and the weights of each point are the weights of the non-tree edges associated with it.
The weight on the top of the tree is the XOR of all points of the sub-tree below it
As a result, some edges (exactly) cut down a subtree to the condition that XOR and =0
It is not difficult to find the number of edges cut each time is very small, 3237 is only 4, you may wish to enumerate all the subsets to see if the exact cut
The remaining two questions have 15, may wish to use linear base maintenance, can combine 0 of the condition is a number useless (sweep to the end has not been added to the linear base)
No, No.
Made this broken Bzoj. Time (0) also reported re, I was transferred all afternoon.
Only 3569 of the code is posted here (the first two are not saved and changed directly)
1#include <bits/stdc++.h>2 using namespacestd;3 intn,m,p,q,e,q;4 structEdge5 {6 int from, to;7} e[1000001];8 structBas9 {Ten inta[ +]; One BOOLOver ; A Bas () - { - for(intI=0; i<= to; i++) thea[i]=0; -Over=0; - } - voidAddintx) + { - if(over)return; + for(intI= to; i>=0; i--) A if(x>>i) at if(A[i]) x^=A[i]; - Else - { -a[i]=x; - return; - } inOver=1; - } to } ret; + intw[1000001],wei[1000001],fa[1000001]; - intnex[1000001],fir[1000001]; the BOOLvis[1000001]; * voidBuildintNowintfat) $ {Panax Notoginsengfa[now]=fat;vis[now]=1; - for(intI=fir[now];i;i=Nex[i]) the if(!vis[e[i].to]) + build (E[i].to,now); A } the intDfsintNow ) + { - for(intI=fir[now];i;i=Nex[i]) $ if(fa[e[i].to]==Now ) $w[now]^=DFS (e[i].to); - returnW[now]; - } the voidAddintXinty) - {WuyiE[++e]. from=x;e[e].to=y;nex[e]=fir[x];fir[x]=E; theE[++e]. from=y;e[e].to=x;nex[e]=fir[y];fir[y]=E; - } Wu intMain () - { Aboutscanf"%d%d",&n,&m); $ for(intI=1; i<=m;i++) -scanf"%d%d",&p,&q), add (p,q); -Build1,0); -Srand2333); A for(intI=1; i<=e;i+=2) + if(Fa[e[i]. from]!=e[i].to && Fa[e[i].to]!=e[i]. from) the { -Wei[i]=rand () *32768+rand (); $W[e[i]. from]^=Wei[i]; thew[e[i].to]^=Wei[i]; the } theDfs1); the - for(intI=1; i<=e;i+=2) in if(Fa[e[i]. from]==e[i].to) theWei[i]=w[e[i]. from]; the Else About if(Fa[e[i].to]==e[i]. from) thewei[i]=w[e[i].to]; the thescanf"%d",&Q); + intkey=0; - for(intI=1; i<=q;i++) the {Bayi if(i==5) the intE=1; thescanf"%d",&p); - //P^=key; -ret=Bas (); the for(intj=1; j<=p;j++) thescanf"%d", &q), q^=Key, theRet.add (wei[q*2-1]); the if(!ret.over) key++; -Puts (ret.over?"Disconnected":"Connected"); the } the return 0; the}
Random algorithm practice bzoj3237&3563&3569 three times times experience problem