-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy path[15]_3.py
More file actions
37 lines (31 loc) · 720 Bytes
/
[15]_3.py
File metadata and controls
37 lines (31 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from collections import deque
n, m = map(int, input().split())
adj = [[] for _ in range(n + 1)]
for _ in range(m):
x, y = map(int, input().split())
adj[y].append(x)
def bfs(v):
q = deque([v])
visited = [False] * (n + 1)
visited[v] = True
count = 1
while q:
v = q.popleft()
for e in adj[v]:
if not visited[e]:
q.append(e)
visited[e] = True
count += 1
return count
result = []
max_value = -1
for i in range(1, n + 1):
c = bfs(i)
if c > max_value:
result = [i]
max_value = c
elif c == max_value:
result.append(i)
max_value = c
for e in result:
print(e, end=" ")