Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
917 B
9
Indexable
Never


def bfs(source ,n ,r ,  pygraph):
  visited = [ 0 for i in range(n + 1)]
  Queue = []
  L = [0 for i in range(n + 1)]
  Queue.append((source  , 0))
  visited[source] = 1
  while(Queue):
    u = Queue.pop(0)
    for i in pygraph[u[0]]:
      if(visited[i] == 0):
        Queue.append((i  ,   u[1] + 1))
        visited[i] = 1
        L[i] = u[1] + 1
 
  count = 0
  if(n ^ 1 == n + 1):
    for i in range(1 , n+ 1):
      if(L[i]  - 2< r):
        count += 1
    return (count)
  else:
    for i in range(1 , n+ 1):
      if(L[i] - 1 < r):
        count += 1
    return (count)

def fun():
  n , r = map(int,input().split())
  pygraph= [[] for i in range(n + 1)]
  for i in range(0, n - 1):
    x , y  = map(int,input().split())
    pygraph[x].append(y)
    pygraph[y].append(x)

  pyset = set()
  for i in range(1 , n + 1): 
    output = bfs(i , n , r  , pygraph)
    pyset.add(output)

  print(len(pyset))

fun()