from collections import deque
n, connections = 6, [[3,6],[4,3],[3,2],[1,3],[1,2],[2,4],[5,2]]
graph = [[] for _ in range(n + 1)]
for a, b in connections:
graph[a].append(b)
graph[b].append(a)
dist = [-1] * (n + 1)
dist[1] = 0
queue = deque([1])
while queue:
node = queue.popleft()
for neighbor in graph[node]:
if dist[neighbor] == -1:
dist[neighbor] = dist[node] + 1
queue.append(neighbor)
max_dist = max(dist[1:])
print(dist[1:].count(max_dist))
To embed this project on your website, copy the following code and paste it into your website's HTML: