jiteshrao

Untitled

Nov 28th, 2020
870
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1e5 + 5;
  5.  
  6. vector<int> v[N];
  7. vector<pair<int, int>> query[N];
  8. int colour[N];
  9. int parent[N];
  10. vector<pair<int, int>> store[N];
  11.  
  12. void dfs1(int sv, int par)
  13. {
  14.     parent[sv] = par;
  15.     for(int x : v[sv])
  16.     {
  17.         if(x == par)
  18.         {
  19.             continue;
  20.         }
  21.         dfs1(x, sv);
  22.     }
  23. }
  24.  
  25. void dfs2(int sv, int & cnt, int col)
  26. {
  27.     cnt += (colour[sv] == col);
  28.     for(int x : v[sv])
  29.     {
  30.         if(x == parent[sv])
  31.         {
  32.             continue;
  33.         }
  34.         dfs2(x, cnt, col);
  35.     }
  36. }
  37.  
  38. int32_t main()
  39. {
  40.     ios_base:: sync_with_stdio(false);
  41.     cin.tie(NULL);
  42.     cout.tie(NULL);
  43.     #ifndef ONLINE_JUDGE
  44.       freopen("input.txt", "r", stdin);
  45.       freopen("output.txt", "w", stdout);
  46.     #endif
  47.     int n, root, query;
  48.     cin >> n >> query >> root;
  49.     for(int i = 0; i < n - 1; i++)
  50.     {
  51.         int a, b;
  52.         cin >> a >> b;
  53.         v[a].push_back(b);
  54.         v[b].push_back(a);
  55.     }
  56.     for(int i = 1; i <= n; i++)
  57.     {
  58.         cin >> colour[i];
  59.     }
  60.     dfs1(root, 0);
  61.     for(int i = 1; i <= query; i++)
  62.     {
  63.         int node, colour;
  64.         cin >> node >> colour;
  65.         store[node].push_back({colour, i});
  66.     }
  67.     for(int i = 1; i <= n; i++)
  68.     {
  69.         cout << ret[i] << " ";
  70.     }
  71. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×