fork download
  1. const int N = 1e5 + 5;
  2. vii v[N];
  3. int par[N];
  4. int p[N];
  5. int vis[N];
  6. int links;
  7.  
  8. void dfs(int node, int pr) {
  9. par[node] = pr;
  10. int x = 1;
  11. for (auto &i : v[node]) {
  12. if (i ^ pr) dfs(i, node);
  13. }
  14. }
  15.  
  16. int power(int n, int p) {
  17. int r = 1;
  18. while (p) {
  19. if (p & 1) r *= n;
  20. r %= mod;
  21. n *= n;
  22. n %= mod;
  23. p /= 2LL;
  24. }
  25. return r;
  26. }
  27.  
  28. void dfss(int u, int pr, set<int>&s) {
  29. vis[u] = 1;
  30. for (auto &i : v[u]) {
  31. if (i ^ pr and !s.count(i)) {
  32. links++;
  33. dfss(i, u, s);
  34. }
  35. }
  36. }
  37.  
  38. void solve()
  39. {
  40. int n, q;
  41. cin >> n >> q;
  42.  
  43. p[0] = 1;
  44. fo(i, 1, n) p[i] = (p[i - 1] * 2LL) % mod;
  45.  
  46. fo(i, 0, n - 2) {
  47. int x, y;
  48. cin >> x >> y;
  49. v[x].pb(y);
  50. v[y].pb(x);
  51. }
  52.  
  53. while (q--) {
  54. int x, y;
  55. cin >> x >> y;
  56. dfs(x, x);
  57. set<int>s;
  58. while (y ^ x) {
  59. s.insert(y);
  60. y = par[y];
  61. }
  62. s.insert(x);
  63.  
  64. links = 0;
  65. fo(i, 1, n) vis[i] = 0;
  66. fo(i, 1, n) {
  67. if (!s.count(i) and !vis[i]) dfss(i, i, s);
  68. }
  69. int ans = power(2LL, links);
  70. cout << ans << endl;
  71. }
  72. }
  73.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:1: error: ‘vii’ does not name a type; did you mean ‘void’?
 vii v[N];
 ^~~
 void
prog.cpp: In function ‘void dfs(int, int)’:
prog.cpp:11:18: error: ‘v’ was not declared in this scope
   for (auto &i : v[node]) {
                  ^
prog.cpp: In function ‘int power(int, int)’:
prog.cpp:20:10: error: ‘mod’ was not declared in this scope
     r %= mod;
          ^~~
prog.cpp: At global scope:
prog.cpp:28:26: error: ‘set’ has not been declared
 void dfss(int u, int pr, set<int>&s) {
                          ^~~
prog.cpp:28:29: error: expected ‘,’ or ‘...’ before ‘<’ token
 void dfss(int u, int pr, set<int>&s) {
                             ^
prog.cpp: In function ‘void dfss(int, int, int)’:
prog.cpp:30:18: error: ‘v’ was not declared in this scope
   for (auto &i : v[u]) {
                  ^
prog.cpp:31:21: error: ‘s’ was not declared in this scope
     if (i ^ pr and !s.count(i)) {
                     ^
prog.cpp: In function ‘void solve()’:
prog.cpp:41:3: error: ‘cin’ was not declared in this scope
   cin >> n >> q;
   ^~~
prog.cpp:44:6: error: ‘i’ was not declared in this scope
   fo(i, 1, n) p[i] = (p[i - 1] * 2LL) % mod;
      ^
prog.cpp:44:3: error: ‘fo’ was not declared in this scope
   fo(i, 1, n) p[i] = (p[i - 1] * 2LL) % mod;
   ^~
prog.cpp:57:5: error: ‘set’ was not declared in this scope
     set<int>s;
     ^~~
prog.cpp:57:9: error: expected primary-expression before ‘int’
     set<int>s;
         ^~~
prog.cpp:59:7: error: ‘s’ was not declared in this scope
       s.insert(y);
       ^
prog.cpp:62:5: error: ‘s’ was not declared in this scope
     s.insert(x);
     ^
prog.cpp:70:5: error: ‘cout’ was not declared in this scope
     cout << ans << endl;
     ^~~~
prog.cpp:70:20: error: ‘endl’ was not declared in this scope
     cout << ans << endl;
                    ^~~~
prog.cpp:70:20: note: suggested alternative: ‘enum’
     cout << ans << endl;
                    ^~~~
                    enum
stdout
Standard output is empty