1 #include2 #include 3 int set[10000005]; 4 int count; 5 #define mod 1000000007 6 7 int find(int x) 8 { 9 int r=x;10 while(r!=set[r])11 r=set[r];12 int i=x;13 while(i!=r)14 {15 int j=set[i];16 set[i]=r;17 i=j;18 }19 return r;20 }21 22 void merge(int x,int y)23 {24 int fx=find(x);25 int fy=find(y);26 if(fx!=fy)27 {28 set[fx]=fy;29 count++;30 }31 }32 33 long long exp(int n){34 long long sum=1, tmp=26;35 while(n){36 if(n&1) //n%2==137 {38 sum = sum*tmp;39 sum %= mod;40 }41 tmp = (tmp*tmp)%mod;42 n>>=1; // n/=2;43 }44 return sum;45 }46 47 int main()48 {49 int n,m,l,r;50 while(scanf("%d%d",&n,&m)!=EOF)51 {52 count=0;53 for(int i=0;i<=n;i++)//i=0,错在i=154 set[i]=i;55 for(int i=1;i<=m;i++)56 {57 scanf("%d%d",&l,&r);58 merge(l-1,r);//若果是l-1,上边初始化就从0开始,如果用merge(l,r+1),初始化i是1到n+159 }60 printf("%lld\n",exp(n-count)%mod);61 }62 return 0;63 }