Submission #1709285


Source Code Expand

n, x = map(int, raw_input().split())
h =  map(int, raw_input().split())
a = [[] for i in xrange(n)]
for i in xrange(n-1) :
    p1, p2 = map(int, raw_input().split())
    a[p1-1].append(p2-1)
    a[p2-1].append(p1-1)

def dfs(pos, back) :
    length = 1
    skip = h[pos] != 1
    for to in a[pos] :
        if to == back :
            continue
        tmp = dfs(to, pos)
        if not tmp[1] :
            skip = False
            length += tmp[0]
    if skip :
        length = 0
    return (length, skip)

print (dfs(x-1, -1)[0] - 1) * 2

Submission Info

Submission Time
Task B - ツリーグラフ
User tatamo
Language Python (2.7.6)
Score 0
Code Size 564 Byte
Status WA
Exec Time 12 ms
Memory 2692 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 19
WA × 1
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask1_line01.txt, subtask1_line02.txt, subtask1_line03.txt, subtask1_line04.txt, subtask1_line05.txt, subtask1_line06.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_random06.txt, subtask1_random07.txt, subtask1_random08.txt, subtask1_special01.txt, subtask1_special02.txt, subtask1_special03.txt, subtask1_special04.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 11 ms 2568 KB
subtask0_sample_02.txt AC 11 ms 2568 KB
subtask1_line01.txt AC 11 ms 2568 KB
subtask1_line02.txt AC 11 ms 2692 KB
subtask1_line03.txt AC 11 ms 2692 KB
subtask1_line04.txt AC 11 ms 2692 KB
subtask1_line05.txt AC 11 ms 2692 KB
subtask1_line06.txt WA 11 ms 2692 KB
subtask1_random01.txt AC 11 ms 2568 KB
subtask1_random02.txt AC 11 ms 2568 KB
subtask1_random03.txt AC 11 ms 2568 KB
subtask1_random04.txt AC 12 ms 2692 KB
subtask1_random05.txt AC 12 ms 2568 KB
subtask1_random06.txt AC 11 ms 2568 KB
subtask1_random07.txt AC 11 ms 2568 KB
subtask1_random08.txt AC 12 ms 2568 KB
subtask1_special01.txt AC 11 ms 2568 KB
subtask1_special02.txt AC 12 ms 2568 KB
subtask1_special03.txt AC 12 ms 2568 KB
subtask1_special04.txt AC 11 ms 2692 KB