Submission #1779419


Source Code Expand

n,s=map(int,input().split())
h=list(map(int,input().split()))
s -= 1
g=[ [] for _ in range(n) ]
for _ in range(n-1):
  a,b=map(int,input().split())
  a -= 1
  b -= 1
  g[a].append(b)
  g[b].append(a)

while True:
  change = False
  for i in range(n):
    if len(g[i]) == 1 and h[i] == 0 and i != s:
      change = True
      a = i
      b = g[i][0]
      g[a].remove(b)
      g[b].remove(a)
  if not change: break
ans = 0
for i in range(n):
  ans += len(g[i])
print(ans)

Submission Info

Submission Time
Task B - ツリーグラフ
User hs484
Language Python (3.4.3)
Score 100
Code Size 496 Byte
Status AC
Exec Time 19 ms
Memory 3064 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 18 ms 3064 KB
subtask0_sample_02.txt AC 18 ms 3064 KB
subtask1_line01.txt AC 18 ms 3064 KB
subtask1_line02.txt AC 18 ms 3064 KB
subtask1_line03.txt AC 18 ms 3064 KB
subtask1_line04.txt AC 18 ms 3064 KB
subtask1_line05.txt AC 18 ms 3064 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 18 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 18 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