Submission #5708264


Source Code Expand

Copy
def dfs(node, distance, ans, G):
    for next_node, edge_size in G[node]:
        if ans[next_node] == -1:
            ans[next_node] = ((distance+edge_size) % 2)
            dfs(next_node, distance+edge_size, ans, G)
    return ans


N = int(input())

G = [[] for i in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    G[u-1].append([v-1, w])
    G[v-1].append([u-1, w])

ans = [-1]*N
ans = dfs(0, 0, ans, G)
print(*ans, sep='\n')

Submission Info

Submission Time
Task D - Even Relation
User upura
Language Python3 (3.4.3)
Score 0
Code Size 476 Byte
Status
Exec Time 827 ms
Memory 46768 KB

Test Cases

Set Name Score / Max Score Test Cases
All 0 / 400 sample_01, sample_02, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_20
Sample 0 / 0 sample_01, sample_02
Case Name Status Exec Time Memory
sample_01 17 ms 3064 KB
sample_02 17 ms 3064 KB
testcase_01 441 ms 31976 KB
testcase_02 254 ms 21764 KB
testcase_03 330 ms 25844 KB
testcase_04 377 ms 28160 KB
testcase_05 691 ms 42052 KB
testcase_06 268 ms 19992 KB
testcase_07 17 ms 3064 KB
testcase_08 17 ms 3064 KB
testcase_09 17 ms 3064 KB
testcase_10 175 ms 14876 KB
testcase_11 28 ms 4080 KB
testcase_12 258 ms 20464 KB
testcase_13 263 ms 20924 KB
testcase_14 260 ms 21248 KB
testcase_15 824 ms 46768 KB
testcase_16 827 ms 46768 KB
testcase_17 762 ms 44884 KB
testcase_18 118 ms 11100 KB
testcase_19 526 ms 33432 KB
testcase_20 165 ms 14672 KB