Advertisement
pb_jiang

ARC148C AC

Feb 1st, 2023
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. // Problem: C - Lights Out on Tree
  2. // Contest: AtCoder - AtCoder Regular Contest 148
  3. // URL: https://atcoder.jp/contests/arc148/tasks/arc148_c
  4. // Memory Limit: 1024 MB
  5. // Time Limit: 3000 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12. #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
  13. template <typename... Args> void logger(string vars, Args &&... values)
  14. {
  15.     cerr << vars << " = ";
  16.     string delim = "";
  17.     (..., (cerr << delim << values, delim = ", "));
  18.     cerr << endl;
  19. }
  20.  
  21. template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
  22. template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
  23. template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
  24. template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
  25.  
  26. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  27.  
  28. using ll = long long;
  29. using pii = pair<int, int>;
  30. using vl = vector<ll>;
  31. using vi = vector<int>;
  32.  
  33. int n, q;
  34. vi fa, cnt;
  35. vi g[200003];
  36.  
  37. int main(int argc, char **argv)
  38. {
  39.     cin >> n >> q;
  40.     cnt = fa = vi(n + 1);
  41.     for (int i = 2; i <= n; ++i)
  42.         cin >> fa[i], g[fa[i]].push_back(i), cnt[fa[i]]++;
  43.     for (int i = 0; i < q; ++i) {
  44.         int m, v;
  45.         cin >> m;
  46.         set<int> vs;
  47.         for (int j = 0; j < m; ++j)
  48.             cin >> v, vs.insert(v);
  49.         int ans = 0;
  50.         for (int u : vs) {
  51.             ans += cnt[u];
  52.             if (vs.count(fa[u]))
  53.                 --ans;
  54.             else
  55.                 ++ans;
  56.         }
  57.         cout << ans << endl;
  58.     }
  59.     return 0;
  60. };
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement