Well ...
through the sample, the answer is either unchanged, or *2+1
then
found that if the new edge Same (l[i].f,l[i].t), *2+1
Proof later, the room will be closed ...
#include <iostream> #include <cstdio> #include <algorithm> #include <
Cstring> using namespace std;
const int MAXN = 200000 + 5;
const int P = 1000000009;
int n,m,p;
int FA[MAXN];
int RANK[MAXN];
void Init () {for (int i = 0;i <= n;i + +) fa[i] = i;
memset (rank,0,sizeof (rank));
Return
} int find (int x) {return fa[x] = = x X:fa[x] = find (fa[x]), void merge (int x,int y) {x = find (x);
y = find (y);
if (x = = y) return;
if (Rank[x] > Rank[y]) swap (x, y);
Fa[x] = y;
if (rank[x] = = Rank[y]) rank[y] + +;
Return
} bool Same (int x,int y) {return find (x) = = Find (y);} int f,t;
int k;
int main () {scanf ("%d%d", &n,&m);
Init ();
while (M-) {scanf ("%d%d", &f,&t);
if (Same (f,t)) K = (k << 1) + 1,k%= P;
printf ("%d\n", K);
Merge (f,t);
} return 0; }