

import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as C
-- import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord(comparing)
import qualified Data.IntMap.Strict as IMap


type Vertex = Int
type Weight = Int

type Graph = IMap.IntMap (U.Vector Edge)
type Edge = (Vertex, Weight)

type VisitedMap = UM.IOVector Bool

r' :: Int -> IO (U.Vector Int)
r' n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

readAsc :: IO (V.Vector (Vertex, U.Vector Edge))
readAsc = do
    uvw <- r' 3
    let u = uvw U.! 0 ; v = uvw U.! 1 ; w = uvw U.! 2
    let s = U.singleton
    case even w of
        True -> return $ V.cons (u,s (v,0)) $ V.singleton (v,s (u,0))
        _    -> return $ V.cons (u,s (v,1)) $ V.singleton (v,s (u,1))


main :: IO ()
main = do
    n <- readLn :: IO Int
    uvw <- V.concat <$> replicateM (n-1) readAsc
    let graph = fromListWithConcat uvw IMap.empty :: Graph
    visited <- UM.replicate n False  
    uores <- solve graph visited 0 1
    res <- UM.new n
    U.forM_ uores (\(f,s)->UM.write res (f-1) s)
    forM_ [0..(n-1)] (\x -> do
            v <- UM.read res x
            print v
        )

fromListWithConcat :: V.Vector (Vertex, U.Vector Edge) -> IMap.IntMap (U.Vector Edge) -> IMap.IntMap (U.Vector Edge)
fromListWithConcat vec mp
    | V.null vec = mp
    | otherwise  = let (k,e) = V.head vec
                    in fromListWithConcat (V.tail vec) $ IMap.insertWith (U.++) k e mp

solve :: Graph -> UM.IOVector Bool -> Weight -> Vertex -> IO (U.Vector Edge)
solve mp visRec curW root = do
    recVisit root visRec
    case IMap.lookup root mp of
        Just xs -> do
            unvisited <- U.filterM ((not <$>) . UM.read visRec . pred . fst) xs
            if unvisited == U.empty
                then do
                    return $ U.singleton (root,curW)
                else do
                    r <- U.foldr' (\(v,w) iob -> do
                                    rest <- solve mp visRec ((w+curW) `mod`2) v
                                    b <- iob
                                    return $ b U.++ rest
                                ) (return U.empty) unvisited 
                    return $ U.cons (root,curW) r
        Nothing -> error ("No entry found for key " ++ show root ++ ".")



recVisit :: Vertex -> UM.IOVector Bool -> IO ()
recVisit v vis = UM.write vis (v-1) True

