{-# OPTIONS_GHC -O2 #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.List
import Data.Char
import qualified Data.Map.Strict as M

convert :: Int -> Int -> VU.Vector (Int,Int,Int) -> V.Vector [(Int,Int)]
convert n e graph = V.create $ do
    v <- VM.replicate n []
    forM_ [0..e-1] $ \i -> do
        let (x,y,w) = graph VU.! i
        VM.modify v ((y-1,w):) (x-1)
        VM.modify v ((x-1,w):) (y-1)
    return v


main :: IO ()
main = do
    n <- readLn
    graph' <- VU.replicateM (n-1) $ (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2)) . VU.unfoldrN 3 (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    let graph = convert n (n-1) graph'
    let v = VU.create $ do
        v <- VUM.replicate n (-1)
        VUM.write v 0 0
        go (zip (graph V.! 0) [0..]) v 
        where go :: [((Int,Int),Int)] -> VUM.MVector s Int -> ST s (VUM.MVector s Int)
              go [] vec         = return vec
              go (((x,w),prev):xs) vec = do
                  xx <- VUM.read vec x
                  if xx /= -1 then go xs vec
                  else do
                      pre <- VUM.read vec prev
                      if even w then VUM.write vec x pre else VUM.write vec x (1-pre)
                      go ((zip (graph V.! x) [x..])++xs) vec
    VU.mapM_ print v