import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    uvw <- replicateM (n-1) $ do
        [u,v,w] <- getIntList
        return (u-1,v-1,w)
    let edge = V.create $ do
            vec <- VM.replicate n []
            forM_ uvw $ \(u,v,w) -> do
                VM.modify vec ((u,w):) v
                VM.modify vec ((v,w):) u
            return vec
    let result = VU.create $ do
            color <- VUM.replicate n (-1 :: Int)
            VUM.write color 0 0
            let go [] = return ()
                go ((par,this,w) : qs) = do
                    c <- VUM.read color par
                    if even w
                    then VUM.write color this c
                    else VUM.write color this ((c+1) `mod` 2)
                    let next = map (\(a,b) -> (this,a,b)) $ filter ((/= par) . fst) (edge V.! this)
                    go (qs ++ next)
            go [(0,0,0)]
            return color
    VU.mapM_ print result