原题
http://codeforces.com/problemset/problem/445/B
//题目大意,输入两个数,n和m,n代表有n个数,m代表有m种关系,接下来输入m行。依次将这些数字放入到一个容器里,
//如果加入的数和前面的数字有关系。则乘2.
//思路,一道并查集。找出哪些数字的父亲节点不是他自己
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define N 55
int father[N];
int n,m;
int find(int x){
int r=x;
while(father[r] != r){
r = father[r];
}
int i = x;
int k;
while(i != r){
k = father[i];
father[i] = r;
i = k;
}
return r;
}
int main(){
int i;
int a,b;
__int64 ans;//第一次做cf木有经验。开始的时候是用int的,wa掉了。。。。
int sum;
while(~scanf("%d%d",&n,&m)){
memset(father,0,sizeof(father));
for(i=1;i<=n;i++)
father[i] = i;
sum = 0;
ans = 1;
for(i=1;i<=m;i++){
scanf("%d%d",&a,&b);
int f1 = find(father[a]);
int f2 = find(father[b]);
if(f1 != f2){
father[f1] = f2;
}
}
for(i=1;i<=n;i++){
if(father[i] != i)
sum++;
}
for(i=1;i<=sum;i++)
ans = ans*2;
printf("%I64d\n",ans);
}
return 0;
}