fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5.  
  6. int n, m;
  7. vector<int> adj[51];
  8. int visited[51];
  9.  
  10. int BFS(int s) {
  11. int cnt = 1;
  12. queue<int> q;
  13.  
  14. q.push(s);
  15. visited[s] = true;
  16.  
  17. while (!q.empty()) {
  18. int u = q.front();
  19. q.pop();
  20.  
  21. for (int v : adj[u]) {
  22. if (!visited[v]) {
  23. cnt += 1;
  24. q.push(v);
  25. visited[v] = true;
  26. }
  27. }
  28. }
  29.  
  30. return cnt;
  31. }
  32.  
  33. int32_t main() {
  34. ios_base::sync_with_stdio(false);
  35. cin.tie(NULL);
  36.  
  37. cin >> n >> m;
  38.  
  39. int res = 1;
  40.  
  41. for (int i = 1, x, y; i <= m; i += 1) {
  42. cin >> x >> y;
  43. adj[x].push_back(y);
  44. adj[y].push_back(x);
  45. }
  46.  
  47. for (int i = 1; i <= n; i += 1) {
  48. if (!visited[i]) {
  49. int Size = BFS(i);
  50. for (int k = 1; k < Size; k += 1) {
  51. res *= 2;
  52. }
  53. }
  54. }
  55.  
  56. cout << res;
  57.  
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
1