{-# LANGUAGE FlexibleContexts, RankNTypes #-}
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
import Data.Ord
import Data.Foldable
import Data.Function
import Debug.Trace
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import Control.Monad.ST

main :: IO ()
main = readLn >>= readContents . pred >>= printRes . solve 
    where
        printRes = mapM_ print

solve :: [[Int]] -> [Int]
solve uvws = V.toList $ V.create (VM.replicate n (0 :: Int) >>= search)
    where
        n = 1 + length uvws

        g = M.fromList . map (\g -> (fst $ head g, map snd g)) . groupBy ((==) `on` fst) . sortOn fst $ concatMap mf uvws
            where
                mf [u, v, w] = [(u - 1, (v - 1, even w)), (v - 1, (u - 1, even w))]

        search vs = vs <$ loop 0 0 0
            where
                loop p i v = mapM_ (\(j, w) -> VM.unsafeWrite vs j w >> loop i j w) cs
                    where
                        cs = map mf . filter (\(j, _) -> j /= p) $ g M.! i
                        mf (j, b)
                            | b = (j, v)
                            | otherwise = (j, 1 - v)
 

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine