P1863[Poetize I] Dark Magician gate time: 1000ms/Space: 131072kib/java class name: main background
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.
Describe
Applepi was imprisoned for only one door, and the locals called it the "Gate of the Dark Magician." This door is painted with a non-right map, and the password to open the door is the figure "the degree of each point is greater than 0 and is even" the number of sub-graphs of 1000000009 modulo value. 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 format
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 format
The output is a total of M lines, indicating the password after each operation.
Test Sample 1 input
4 8
3 1
3 2
2 1
2 1
1 3
1 4
2 4
2 3
Output
0
0
1
3
7
7
15
to
Note
After the third addition, there is a sub-diagram that satisfies the criteria {1, 2, 3} (where 1, 2, 3 is the label of the "Edge" in the data).
After adding the fourth time, there are three sub-graphs {1, 2, 3},{1, 2, 4},{3, 4}.
......
For 30% of data, N, m≤10.
For 100% of data, n≤200000,m≤300000.
Reminder: Sub-graphs are not necessarily connected. To give another example, such as points (1, 2, 3), (4, 5, 6), each of which consists of a ternary ring, there are three sub-graphs in the figure.
After analyzing a wave, you can know that each side, if connected before two o'clock, then ans=ans*2+1
Use and check set maintenance can be
But! But why, Tle! I have done the optimization, why the tle!
----PostScript: TYVJ toxic, replaced by codevs seconds. Spicy Chicken OJ Station wasted my time to ruin my youth
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cmath>5 using namespacestd;6 intfa[200010];7 intn,m;8 Long Longans=0;9 TenInlineintRead () { One intx=0;CharCh=GetChar (); A while(ch<'0'|| Ch>'9') ch=GetChar (); - while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} - returnx; the } -InlineintFindintx) {//And look up the parent node for the collection - if(fa[x]==x)returnx; - Else returnfa[x]=find (Fa[x]); + } - intMain () { +N=read (); m=read (); A inti; at for(i=1; i<=n;i++) fa[i]=i; - for(i=1; i<=m;i++){ - intA=find (Read ()), b=Find (Read ()); - if(a==b) -{ans= (ans<<1)+1; - if(ans>=1000000009) ans-=1000000009;} in Elsefa[b]=A; -printf"%lld\n", ans); to } + return 0; -}
CODEVS1995 | | TYVJ1863 Black Magician's Gate