-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathd.cc
41 lines (36 loc) · 718 Bytes
/
d.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// https://atcoder.jp/contests/abc126/tasks/abc126_d
#include <bits/stdc++.h>
using namespace std;
using ii = tuple<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvii = vector<vii>;
int n, u, v, w;
vi c;
vvii g;
void dfs(int u, int p) {
for (ii &x : g[u]) {
tie(v, w) = x;
if (v != p) {
if (w % 2) c[v] = !c[u];
else c[v] = c[u];
dfs(v, u);
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
g = vvii(n);
for (int i = 0; i < n - 1; i++) {
cin >> u >> v >> w;
u--, v--;
g[u].push_back(make_tuple(v, w));
g[v].push_back(make_tuple(u, w));
}
c = vi(n);
c[0] = 0;
dfs(0, -1);
for (int x : c) cout << x << "\n";
}