import           Control.Monad
import           Data.Array.IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           System.IO

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

getEdges evenEs oddEs = do
  [u, v, w] <- getIntList
  let evenEs' = if w `mod` 2 == 0 then (u, v) : evenEs else evenEs
      oddEs' = if w `mod` 2 == 0 then oddEs else (u, v) : oddEs
  eof <- isEOF
  if eof
    then return (evenEs', oddEs')
    else getEdges evenEs' oddEs'

main = do
  n <- getInt
  (evenEs, oddEs) <- getEdges [] []

  cs <- VM.new n
  VM.set cs (-1 :: Int)

  forM_ oddEs $ \(u, v) -> do
    ucol <- VM.read cs (u-1)
    vcol <- VM.read cs (v-1)
    let (ucol', vcol') = newCols ucol vcol 1
    VM.write cs (u-1) ucol'
    VM.write cs (v-1) vcol'

  forM_ evenEs $ \(u, v) -> do
    ucol <- VM.read cs (u-1)
    vcol <- VM.read cs (v-1)
    let (ucol', vcol') = newCols ucol vcol 0
    VM.write cs (u-1) ucol'
    VM.write cs (v-1) vcol'

  forM_ [0..(n-1)] $ \i -> do
    c <- VM.read cs i
    print c

newCols (-1) (-1) 0 = (0, 0)
newCols (-1) (-1) 1 = (0, 1)
newCols (-1) vcol 0 = (vcol, vcol)
newCols (-1) vcol 1 = ((vcol+1) .&. 1, vcol)
newCols ucol (-1) 0 = (ucol, ucol)
newCols ucol (-1) 1 = (ucol, (ucol+1) .&. 1)
newCols ucol vcol _ = (ucol, vcol)