1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <string>6#include <queue>7#include <algorithm>8#include <map>9#include <iomanip>Ten#include <climits> One#include <string.h> A#include <numeric> -#include <cmath> -#include <stdlib.h> the#include <vector> -#include <stack> -#include <Set> - #defineFor (x, B, E) for (int x=b;x<= (e); x + +) + #defineREP (x, N) for (int x=0;x< (n); x + +) - #defineMAXN 100010 + #defineMAXN 1000010 A #defineMod 1000007 at #defineN 1010 - using namespacestd; -typedefLong LongLL; - - intN, M; - inteax10000010]; in intCNT; - to intFindset (intx) + { - returnFA[X] = fa[x] = = x?X:findset (fa[x]); the } * $ voidMergeintAintb)Panax Notoginseng { - intx =Findset (a); the inty =Findset (b); + if(X! =y) { AFA[X] =y; thecnt++; + } - } $ $LL Quick_pow (intN) - { -LL tmp = -, sum =1; the while(n) { - if(N &1) sum = (SUM * tmp)%1000000007; WuyiTMP = (TMP * tmp)%1000000007; theN >>=1; - } Wu returnSum%1000000007; - } About $ intMain () - { - intL, R; - while(Cin >> N >>m) { ACNT =0; +for (I,0, n) fa[i] =i; thefor (I,1, M) { -CIN >> L >>R; $Merge (L-1, R); the } thecout << Quick_pow (n-cnt) <<Endl; the } the return 0; -}
HDU 3461 Code Lock