-- import qualified Data.Vector.Unboxed as U
-- import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
-- import Data.Array.IO
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord(comparing)
-- import Data.Char
import qualified Data.Map.Strict as Map
-- import Data.Graph


type Vertex = Int
type Weight = Int

type Graph = Map.Map Vertex [(Vertex, Weight, Visited)]
type Visited = Bool
{-
collapseW :: Int -> Tree -> [(Weight, Vertex)]
collapseW wac (Node (w,v) []) = [(w+wac,v)] 
collapseW wac (Node (w,v) xs) =  (w+wac,v) : concat (map (collapseW (w+wac)) xs)
-}
{--
r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine
-}
r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

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


main :: IO ()
main = do
    n <- readLn :: IO Int
    uvw <- concat <$> replicateM (n-1) readAsc
    let graph = Map.fromListWith fsNubConcat uvw
    -- print graph
    let res = solve graph 0 1
    print 0
    mapM_ print $ map snd $ (sortBy $ comparing fst) res
    -- print res



solve :: Graph -> Weight -> Vertex -> [(Vertex,Weight)]
solve mp curW root = {-traceShow (mp,curW,root) $-} case Map.lookup root mp of
                    Just xs -> let unvisited = filter (\(v,w,b)->not b) xs 
                                in if unvisited == [] then []
                                    else concat $ map (\(v,w,b) ->
                                            let newW = (w+curW) `mod`2
                                            in (root,w):solve (recVisit root v newW mp) newW v 
                                        ) unvisited
                    Nothing -> error ("No entry with key " ++ show root ++ " found.")



recVisit :: Vertex -> Vertex -> Weight -> Graph -> Graph
recVisit u v w = (Map.insertWith fsNubConcat u [(v,w,True)] . Map.insertWith fsNubConcat v [(u,w,True)])



fsNubConcat a b = nubBy (\(a,b,_)(x,y,_)->a==x && b==y) (a++b)

