top of page

소스 코드 제출

공개·회원 50명

20250619


import sys

sys.setrecursionlimit(10**6)

def dfs(x):

global n,k,a,ans,b

b[x]=1

md=0

sd=0

c=[]

for i in a[x]:

if b[i]==1:

continue

t=dfs(i)

if t!=-1:

c.append(t+1)

c.sort(reverse=True)

if len(c)>=2 and c[0]+c[1]>=k:

shell[x]=1

ans+=1

return -1

else:

if c:

return c[0]

else:

return 0

n,k=map(int,input().split())

a=[[]for i in range(n+1)]

b=[0 for i in range(n+1)]

for i in range(n-1):

x,y=map(int,input().split())

a[x].append(y)

a[y].append(x)

shell=[0 for i in range(n+1)]

ans=0

r=0

dfs(1)

print(sum(shell))

2회 조회
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546 ,     031) 215 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호
bottom of page