标签:
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> 10 #include<climits> 11 #include<string.h> 12 #include<numeric> 13 #include<cmath> 14 #include<stdlib.h> 15 #include<vector> 16 #include<stack> 17 #include<set> 18 #define FOR(x, b, e) for(int x=b;x<=(e);x++) 19 #define REP(x, n) for(int x=0;x<(n);x++) 20 #define MAXN 100010 21 #define maxn 1000010 22 #define Mod 1000007 23 #define N 1010 24 using namespace std; 25 typedef long long LL; 26 27 int n, m; 28 int fa[10000010]; 29 int cnt; 30 31 int findset(int x) 32 { 33 return fa[x] = fa[x] == x? x:findset(fa[x]); 34 } 35 36 void merge(int a, int b) 37 { 38 int x = findset(a); 39 int y = findset(b); 40 if (x != y) { 41 fa[x] = y; 42 cnt++; 43 } 44 } 45 46 LL quick_pow(int n) 47 { 48 LL tmp = 26,sum = 1; 49 while (n) { 50 if (n & 1) sum = (sum * tmp) % 1000000007; 51 tmp = (tmp * tmp) % 1000000007; 52 n >>= 1; 53 } 54 return sum % 1000000007; 55 } 56 57 int main() 58 { 59 int l, r; 60 while (cin >> n >> m) { 61 cnt = 0; 62 FOR(i,0,n) fa[i] = i; 63 FOR(i,1,m) { 64 cin >> l >> r; 65 merge(l-1,r); 66 } 67 cout << quick_pow(n - cnt) << endl; 68 } 69 return 0; 70 }
标签:
原文地址:http://www.cnblogs.com/usedrosee/p/4378681.html