Submission #287195


Source Code Expand

Copy
n,x = map(int,raw_input().split())
takara = map(int,raw_input().split())
g=[]
for i in xrange(n-1):
    g.append(map(int,raw_input().split()))

# print g

def dfs(now):

    s=0

    for e in g:
        if e[0]==now:
            g.remove(e)
            s+=dfs(e[1])

    for e in g:
        if e[1]==now:
            g.remove(e)
            s+=dfs(e[0])

    if (s>0 or takara[now-1]==1) and now!=x:
        s+=1


    return s

print dfs(x)*2
# print g

Submission Info

Submission Time
Task B - ツリーグラフ
User richard
Language Python (2.7.3)
Score 0
Code Size 484 Byte
Status WA
Exec Time 54 ms
Memory 3392 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 10
WA × 10
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 51 ms 3380 KB
subtask0_sample_02.txt AC 51 ms 3380 KB
subtask1_line01.txt AC 50 ms 3384 KB
subtask1_line02.txt AC 50 ms 3324 KB
subtask1_line03.txt AC 50 ms 3388 KB
subtask1_line04.txt AC 51 ms 3380 KB
subtask1_line05.txt AC 51 ms 3384 KB
subtask1_line06.txt AC 51 ms 3384 KB
subtask1_random01.txt WA 52 ms 3376 KB
subtask1_random02.txt WA 49 ms 3376 KB
subtask1_random03.txt WA 50 ms 3380 KB
subtask1_random04.txt WA 53 ms 3388 KB
subtask1_random05.txt WA 51 ms 3324 KB
subtask1_random06.txt WA 50 ms 3392 KB
subtask1_random07.txt WA 52 ms 3380 KB
subtask1_random08.txt WA 51 ms 3388 KB
subtask1_special01.txt AC 52 ms 3388 KB
subtask1_special02.txt WA 51 ms 3384 KB
subtask1_special03.txt WA 54 ms 3308 KB
subtask1_special04.txt AC 52 ms 3380 KB