Submission #1498953


Source Code Expand

n,x = map(int,input().split())
x -= 1
h = list(map(int, input().split()))
edge = [[] for i in range(n)]
#child = [[] for i in range(n)]
parent = [x for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

search = [x]
rest = [i for i in range(n)]
rest.remove(x)
while len(search) > 0:
    node = search[0]
    search.pop(0)
    e = edge[node]
    for v in e:
        if v in rest:
            parent[v] = node
            search.append(v)
            rest.remove(v)
path = []
for i in range(n):
    if h[i] == 0 or i == x:
        continue
    v = i
    while parent[v] != x:
        path.append((v,parent[v]))
        v = parent[v]
    path.append((v,parent[v]))

path = list(set(path))

print(len(path) * 2)

Submission Info

Submission Time
Task B - ツリーグラフ
User yuzupom
Language Python (3.4.3)
Score 100
Code Size 831 Byte
Status AC
Exec Time 21 ms
Memory 3316 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 20
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 19 ms 3192 KB
subtask0_sample_02.txt AC 18 ms 3064 KB
subtask1_line01.txt AC 17 ms 3064 KB
subtask1_line02.txt AC 21 ms 3188 KB
subtask1_line03.txt AC 18 ms 3064 KB
subtask1_line04.txt AC 20 ms 3188 KB
subtask1_line05.txt AC 21 ms 3316 KB
subtask1_line06.txt AC 18 ms 3064 KB
subtask1_random01.txt AC 18 ms 3064 KB
subtask1_random02.txt AC 18 ms 3064 KB
subtask1_random03.txt AC 18 ms 3064 KB
subtask1_random04.txt AC 19 ms 3064 KB
subtask1_random05.txt AC 18 ms 3064 KB
subtask1_random06.txt AC 19 ms 3064 KB
subtask1_random07.txt AC 18 ms 3064 KB
subtask1_random08.txt AC 18 ms 3064 KB
subtask1_special01.txt AC 17 ms 3064 KB
subtask1_special02.txt AC 18 ms 3064 KB
subtask1_special03.txt AC 18 ms 3064 KB
subtask1_special04.txt AC 18 ms 3064 KB