module Main where

    import Data.List
    import Control.Monad
    import Debug.Trace
    import qualified Data.Vector.Mutable as MV
    import Control.Monad.ST (runST)
    import qualified Data.ByteString.Char8 as BC
    import Data.Maybe (fromJust)
    
    readTuple2 :: IO (Int, Int)
    readTuple2 = do
        [a, b] <- words <$> getLine
        return (read a, read b)
    
    readTuple3 :: IO (Int, Int, Int)
    readTuple3 = do
        [a, b, c] <- fmap (fst. fromJust . BC.readInt) . BC.words <$> BC.getLine
        return (a, b, c)
    
    main = do
        n <- readLn
        distantVec <- MV.replicate n []
        let root = 0
        replicateM_ (n - 1) $ do
            (from, to, distance) <- readTuple3
            MV.modify distantVec (((to-1), distance `mod` 2):) (from  -1)
            MV.modify distantVec (((from-1), distance `mod` 2):) (to  -1)
        distanceFromRootVec <- MV.replicate n (Nothing :: Maybe Int)
        let search point distAccum = do
                MV.write distanceFromRootVec point (Just distAccum)
                routes <- MV.read distantVec point
                forM_ routes $ \(nextPoint, distance) -> do
                    dist <- MV.read distanceFromRootVec nextPoint 
                    case dist of
                        Just n -> pure ()
                        Nothing -> search nextPoint ((distAccum + distance) `mod` 2)
        search root 0
        forM [0..(n - 1)] $ \point -> do
            dist <- MV.read distanceFromRootVec point
            case dist of
                Nothing -> putStrLn "-1"
                Just n -> putStrLn $ if even n then "0" else "1"