-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOJ_1325.py
76 lines (70 loc) · 1.55 KB
/
BOJ_1325.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# import sys
# input = sys.stdin.readline
# from collections import deque
#
# def dfs(graph, start):
# que = deque()
# que.append(start)
# visit = []
#
# while que:
# node = que.popleft()
# if node not in visit:
# visit.append(node)
# if node in graph:
# que.extend(graph[node])
# return len(visit)
#
# graph = {}
# n, m = map(int, input().split())
# for _ in range(m):
# x, y = map(int, input().split())
# if y in graph:
# graph[y].append(x)
# else:
# graph[y] = [x]
#
# len_list = []
# temp_max = 0
# for i in range(n):
# temp = dfs(graph, i+1)
# if temp_max < temp:
# len_list = [i+1]
# temp_max = temp
# elif temp_max == temp:
# len_list.append(i+1)
#
# print(*len_list)
import sys
input = sys.stdin.readline
from collections import deque
def bfs(start):
q = deque()
q.append(start)
visit = [0 for _ in range(n + 1)]
visit[start] = 1
cnt = 1
while q:
st = q.popleft()
for i in graph[st]:
if visit[i] == 0:
visit[i] = 1
cnt += 1
q.append(i)
return cnt
n, m = map(int, input().split())
graph = [[] for _ in range(n+1)]
for _ in range(m):
x, y = map(int, input().split())
graph[y].append(x)
len_list = []
temp_max = 0
for i in range(1, n+1):
temp = bfs(i)
if temp_max == temp:
len_list.append(i)
if temp_max < temp:
len_list = []
len_list.append(i)
temp_max = temp
print(*len_list)