Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define SYNC ios::sync_with_stdio(0);
- #define F first
- #define S second
- #define endl '\n'
- using namespace std;
- using ll = long long int;
- using ii = pair<int, int>;
- using vii = vector<ii>;
- using vi = vector<int>;
- using graph = vector<vi>;
- const int INF = 0x3f3f3f3f;
- const int MAXN = 209877;
- const ll mod = 1000000007;
- vector<vii> g;
- vi seen;
- vi cor;
- void dfs (int idx) {
- seen[idx] = 1;
- for (auto i : g[idx]) {
- if (!seen[i.first]) {
- if (i.second%2 == 0) {
- cor[i.first] = cor[idx];
- } else {
- cor[i.first] = !cor[idx];
- }
- dfs(i.first);
- }
- }
- }
- int main() {
- SYNC
- int n, v, u, w;
- cin >> n;
- g.assign(n+1, vector<ii>());
- for (int i = 1; i < n; ++i) {
- cin >> v >> u >> w;
- g[v].push_back(make_pair(u, w));
- g[u].push_back(make_pair(v, w));
- }
- seen.assign(n+1, 0);
- cor.assign(n+1, 0);
- dfs(1);
- for (int i = 1; i <= n; ++i) {
- cout << cor[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment