yeonho12345   11달 전

import sys

input=sys.stdin.readline

sys.setrecursionlimit(10**9)

def DFS(no,ll):

global to

vi[no]=True

if ll<=K and ap[no]==1:

to+=1

for i in tr[no]:

if not vi[i]:

DFS(i,ll+1)

N,K=map(int,input().split())

tr=[ [] for _ in range(N+1) ]

for i in range(N-1):

p,c=map(int,input().split())

tr[p].append(c)

tr[c].append(p)

ap=list(map(int,input().split()))

vi=[False]*(N+1)

to=0

DFS(0,0)

print(to)

댓글을 작성하려면 로그인해야 합니다.