Problem:
Score : 400 points

Problem Statement

We have a tree with N vertices numbered 1 to N.
The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i.
Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:

For any two vertices painted in the same color, the distance between them is an even number.

Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq u_i < v_i \leq N

1 \leq w_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1}

Output

Print a coloring of the vertices that satisfies the condition, in N lines.
The i-th line should contain 0 if Vertex i is painted white and 1 if it is painted black.

If there are multiple colorings that satisfy the condition, any of them will be accepted.

Sample Input 1

3
1 2 2
2 3 1

Sample Output 1

0
0
1

Sample Input 2

5
2 5 2
2 3 10
1 3 8
3 4 2

Sample Output 2

1
0
1
0
1

Solution in Rust (1.15.1) (judge verdict: Accepted)

#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    }
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[derive(Clone)]
struct Edge(usize, usize);

struct Solver {
    color: Vec<usize>,
}

const DUMMY: usize = 9;

impl Solver {
    fn new(N: usize) -> Solver {
        Solver { color: vec![DUMMY; N] }
    }
    fn dfs(&mut self, i: usize, p: usize, acc: usize, g: &Vec<Vec<Edge>>) {
        if self.color[i] != DUMMY {
            return;
        }
        self.color[i] = acc;
        for &Edge(to, w) in &g[i] {
            if to == p {
                continue;
            }
            self.dfs(to, p, acc ^ w, g);
        }
    }
}

use std::iter::IntoIterator;

fn join_string<T, S>(elems: T) -> String
where
    T: IntoIterator<Item = S>,
    S: ToString,
{
    elems
        .into_iter()
        .map(|i| i.to_string())
        .collect::<Vec<String>>()
        .join(" ")
}

fn main() {
    input!{
        N: usize,
        uvw: [(usize1, usize1, usize); N-1],
    }
    let mut graph = vec![Vec::new(); N];
    for (u, v, w) in uvw {
        let w = w % 2;
        graph[u].push(Edge(v, w));
        graph[v].push(Edge(u, w));
    }
    let mut s = Solver::new(N);
    s.dfs(0, N+1, 0, &graph);
    for i in s.color {
        println!("{}", i);
    }
}