and check Set
The gate of the Black Magician |
Question Description |
After 16 working days of intense hectic, the future of mankind has finally collected enough energy. However, in the war with Violet, because of the stupidity of Lieutenant Z, the Earth leader Applepi was imprisoned by the evil black magician Vani on the Violet Planet. In order to restart are available this magnificent science and technology project, Human sent a xlk, poet_shy and Lydrainbowcat composed of three elite team, through the space-time tunnel, to Violet Planet to save leader Applepi. Applepi was imprisoned for only one door, and the locals called it the "Gate of the Dark Magician." The door is painted with a non-right map, and the opening of the door is the number of each point in the figure of more than 0 degrees and are all even-numbered sub-graph of the value of 1000000009 modulo. Here the sub-diagram (V, E) is defined as: the point set V and the edge set E are any subset of the original, where the ends of the edges in E are in V. But vani that such a password is too simple, so the diagram on the door is dynamic. Initially there are only n vertices and no edges in the graph. The gating system built by Vani operates m times, adding an edge to the diagram each time. You must fill in the correct password after each operation to open the Black magician's prison and save the great leader Applepi. |
Input |
The first line contains two integers of N and M. Next M line, two integers a and b per line, represents a non-forward edge (A, b) for the gating system. |
Output |
A total of M lines, indicating the password after each operation. |
Input example |
4 8 3 1 3 2 2 1 2 1 1 3 1 4 2 4 2 3 |
Output example |
0 0 1 3 7 7 15 31 |
Other Notes |
Data range: n≤200000, m≤300000. |
1#include <iostream>2 #defineP 10000000093 using namespacestd;4 intRead ()5 { 6 intf=0;7 Charx;x=GetChar ();8 while(x<'0'|| X>'9') x=GetChar ();9 while(x>='0'&&x<='9')Ten { Onef=f*Ten+x-'0'; Ax=GetChar (); - } - returnF; the } - intfa[200001]; - intFindintx) {returnx==fa[x]?x:fa[x]=find (Fa[x]);} - intMain () + { - intn,m; + intans=1; AN=read (), m=read (); at for(intI=1; i<=n;i++) fa[i]=i; - for(intI=1; i<=m;i++) - { - intb; -A=read (), b=read (); - intA1=find (a), b1=find (b); in if(A1==B1) ans*=2; - Elsefa[a1]=Fa[b]; toprintf"%d\n", (ans-1)%p); +ans%=p; - } the}
View Code
The gate of the Black Magician