Jeremiah_

ABC_126 - D - Even Relation

Jun 11th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define SYNC ios::sync_with_stdio(0);
  4. #define F first
  5. #define S second
  6. #define endl '\n'
  7.  
  8.  
  9. using namespace std;
  10.  
  11. using ll = long long int;
  12. using ii = pair<int, int>;
  13. using vii = vector<ii>;
  14. using vi = vector<int>;
  15. using graph = vector<vi>;
  16. const int INF = 0x3f3f3f3f;
  17. const int MAXN = 209877;
  18. const ll mod = 1000000007;
  19.  
  20. vector<vii> g;
  21.  
  22. vi seen;
  23. vi cor;
  24.  
  25. void dfs (int idx) {
  26.     seen[idx] = 1;
  27.     for (auto i : g[idx]) {
  28.         if (!seen[i.first]) {
  29.             if (i.second%2 == 0) {
  30.                 cor[i.first] = cor[idx];
  31.             } else {
  32.                 cor[i.first] = !cor[idx];
  33.             }
  34.             dfs(i.first);
  35.         }
  36.     }
  37. }
  38.  
  39. int main() {
  40.     SYNC
  41.     int n, v, u, w;
  42.     cin >> n;
  43.     g.assign(n+1, vector<ii>());
  44.     for (int i = 1; i < n; ++i) {
  45.         cin >> v >> u >> w;
  46.         g[v].push_back(make_pair(u, w));
  47.         g[u].push_back(make_pair(v, w));
  48.     }
  49.     seen.assign(n+1, 0);
  50.     cor.assign(n+1, 0);
  51.     dfs(1);
  52.     for (int i  = 1; i <= n; ++i) {
  53.         cout << cor[i] << endl;
  54.     }
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment