
import qualified Data.Vector.Unboxed as U
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 [Edge]
type Edge = (Vertex, Weight)

type VisitedMap = UM.IOVector Bool

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

readAsc :: IO [(Vertex,[Edge])]
readAsc = do
    [u,v,w] <- r'
    case even w of
        True -> return [ (u,[(v,0)]), (v,[(u,0)]) ]
        _    -> return [ (u,[(v,1)]), (v,[(u,1)]) ]


main :: IO ()
main = do
    n <- readLn :: IO Int
    uvw <- concat <$> replicateM (n-1) readAsc :: IO [(Vertex,[Edge])]
    let graph = IMap.fromListWith (\a b -> nub (a++b)) uvw :: Graph
    visited <- UM.replicate n False  
    -- print graph
    res <- solve graph visited 0 1
    mapM_ print $ map snd $ (sortBy $ comparing fst) res
    -- print res



solve :: Graph -> UM.IOVector Bool -> Weight -> Vertex -> IO [Edge]
solve mp visRec curW root = do
    recVisit root visRec
    case IMap.lookup root mp of
        Just xs -> do
            unvisited <- filterM ((not <$>) . UM.read visRec . pred . fst) xs
            if unvisited == []
                then do
                    return [(root,curW)]
                else do
                    r <-forM unvisited (\(v,w) -> do
                            let newW = (w+curW) `mod`2
                            solve mp visRec newW v
                        )
                    return $ (root,curW):concat 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

