Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define optimizar ios_base::sync_with_stdio(0); cin.tie(0)
  3. #define lld long long int
  4. #define MAXN 52
  5. using namespace std;
  6.  
  7. lld resp = 1;
  8.  
  9. int n, m;
  10.  
  11. int x, y;
  12. int fa[MAXN];
  13.  
  14. vector < int > lista[MAXN];
  15.  
  16. int busca(int x) {
  17. while (x != fa[x])
  18. x = fa[x];
  19. return x;
  20. }
  21.  
  22. int main()
  23. {
  24. optimizar;
  25.  
  26. cin >> n >> m;
  27.  
  28. for (int i = 1; i <= n; i++)
  29. fa[i] = i;
  30.  
  31. while (m--) {
  32. cin >> x >> y;
  33. int fa_x = busca(x);
  34. int fa_y = busca(y);
  35. fa[fa_x] = fa_y;
  36. }
  37. lld resp = (1LL << n);
  38. for (int i = 1; i <= n; i++) {
  39. if (busca(i) == i)
  40. resp >>= 1;
  41. }
  42.  
  43. cout << resp << "\n";
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement