Problem:
Score : 400 points

Problem Statement

We have a tree with N vertices numbered 1 to N.
The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i.
Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:

For any two vertices painted in the same color, the distance between them is an even number.

Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq u_i < v_i \leq N

1 \leq w_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1}

Output

Print a coloring of the vertices that satisfies the condition, in N lines.
The i-th line should contain 0 if Vertex i is painted white and 1 if it is painted black.

If there are multiple colorings that satisfy the condition, any of them will be accepted.

Sample Input 1

3
1 2 2
2 3 1

Sample Output 1

0
0
1

Sample Input 2

5
2 5 2
2 3 10
1 3 8
3 4 2

Sample Output 2

1
0
1
0
1

Solution in Lua (5.3.2) (judge verdict: Accepted)

local DBG = true
local function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

local function dbgpr_t(tbl, use_pairs)
    if DBG then
        local enum = ipairs
        if use_pairs then
            enum = pairs
        end
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in enum(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end

local function use_strict()
    local mt = {
        __index = function(t,k) error("_G __index:" .. k) end,
        __newindex = function(t,k,v) error("_G __newindex:" .. k) end
    }
    setmetatable(_G, mt)
end

-- http://www.lua.org/pil/11.4.html
List = {}
function List.new()
    return setmetatable({first = 0, last = -1}, {__index = List})
end

--[[
function List:pushleft(value)
    local first = self.first - 1
    self.first = first
    self[first] = value
end
]]

function List:pushright(value)
    local last = self.last + 1
    self.last = last
    self[last] = value
end

function List:popleft()
    local first = self.first
    if first > self.last then error("list is empty") end
    local value = self[first]
    self[first] = nil        -- to allow garbage collection
    self.first = first + 1
    return value
end

--[[
function List:popright()
    local last = self.last
    if self.first > last then error("list is empty") end
    local value = self[last]
    self[last] = nil         -- to allow garbage collection
    self.last = last - 1
    return value
end
]]

function List:count()
    return self.last - self.first + 1
end
--
use_strict()
local N = io.read("n")
local weights = {}
local adj_list = {}
for i=1,N do
    adj_list[i] = {}
end
local function key(u,v)
    return u .. "," .. v
end
local function getw(u,v)
    return weights[key(u,v)] or weights[key(v,u)]
end
for i=1,N-1 do
    local u,v,w = io.read("n", "n", "n")
    weights[key(u,v)] = w
    table.insert(adj_list[u], v)
    table.insert(adj_list[v], u)
end

local distance_from_1 = {}
distance_from_1[1] = 0
do
    local seen = {}
    seen[1] = true
    local accum = 0
    local q = List.new()
    q:pushright(1)
    local count = 1
    while count < N do
        local from = q:popleft()
        local w_before = distance_from_1[from]
        for _, to in ipairs(adj_list[from]) do
            if not seen[to] then
                seen[to] = true
                local w = getw(from, to)
                distance_from_1[to] = w_before + w
                count = count + 1
                q:pushright(to)
            end
        end
    end
end
--dbgpr_t(distance_from_1)
for i=1,N do
    if distance_from_1[i] % 2 == 0 then
        print(0)
    else
        print(1)
    end
end