#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn readu() -> usize {
    read::<usize>()
}

#[allow(dead_code)]
fn readi() -> i32 {
    read::<i32>()
}

#[derive(Clone)]
struct Edge {
    to: usize,
    weight: usize,
}

fn solve(pos: usize, color: usize, colors: &mut Vec<usize>, graph: &Vec<Vec<Edge>>) {
    colors[pos] = color;
    for edge in &graph[pos] {
        if edge.to == pos {
            continue;
        }
        if colors[edge.to] > 0 {
            continue;
        }

        if edge.weight % 2 == 1 {
            solve(edge.to, 3 - color, colors, graph);
        } else {
            solve(edge.to, color, colors, graph);
        }
    }
}

fn main() {
    input! {
        n: usize,
        uvw: [(usize, usize, usize); n-1],
    }

    let mut graph = vec![vec![]; n];
    let mut colors = vec![0; n];
    for &(u, v, w) in &uvw {
        graph[u - 1].push(Edge {
            to: v - 1,
            weight: w,
        });
        graph[v - 1].push(Edge {
            to: u - 1,
            weight: w,
        });
    }
    solve(0, 1, &mut colors, &graph);

    for color in &colors {
        println!("{}", color - 1);
    }
}

Measured memory_bytes: 21884