{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

unew :: VU.Unbox a => Int -> VUM.IOVector a
unew !n = accursedUnutterablePerformIO $ VUM.unsafeNew n

uread :: VU.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VU.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

umodify :: VU.Unbox a => Int -> (a -> a) -> VUM.IOVector a -> VUM.IOVector a
umodify !i !f !v =
  accursedUnutterablePerformIO $ VUM.unsafeModify v f i >> return v

uthaw :: VU.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VU.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uset :: VU.Unbox a => a -> VUM.IOVector a -> VUM.IOVector a
uset !i !v = accursedUnutterablePerformIO $ VUM.set v i >> return v

solve :: Int -> VU.Vector (Int, Int, Int) -> VU.Vector Int
solve !n !uvw = ufreeze $ (\(_, _, !y, _) -> y) $ dfs
 where
  dfs = fix
    (\(!f) (!parent, !node, !acc, !cost) ->
      let edges = filter (\(e, _) -> parent /= e) $ graph V.! node
      in  if null edges
            then (parent, node, acc, cost)
            else (\(!y) -> (parent, node, y, cost)) $ foldl'
              (\(!acc) (!e, !c) ->
                let acc' = if odd (cost + c) then uwrite e 1 acc else acc
                in  (\(_, _, !y, _) -> y) $ f (node, e, acc', cost + c)
              )
              acc
              edges
    )
    (-1, 0, uset 0 $ unew n, 0)

  graph :: V.Vector [(Int, Int)]
  graph = V.accumulate (flip (:)) (V.replicate n []) $ V.convert $ VU.concatMap
    (\(x, y, z) -> VU.fromList [(x, (y, z)), (y, (x, z))])
    uvw

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n   <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  uvw <-
    VU.replicateM (n - 1)
    $   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1, vec VU.! 2))
    .   VU.unfoldrN 3 readInt
    <$> B.getLine
  VU.mapM_ print $ solve n uvw
