🏷 문제

💡 코드
from sys import stdin
from collections import deque
N, M = map(int, stdin.readline().split())
graph = [ [] for _ in range(N+1) ]
def find(x):
q = deque()
q.append(x)
visited = [0] * (N+1)
visited[x] = 1
cnt = 1
while q:
newx = q.popleft()
for com in graph[newx]:
if visited[com] == 0:
visited[com] = 1
q.append(com)
cnt += 1
return cnt
for _ in range(M):
x, y = map(int, stdin.readline().split())
graph[y].append(x)
res_list = []
max_tmp = -1e9
for idx in range(1, N+1):
res = find(idx)
if res > max_tmp:
res_list = [idx]
max_tmp = res
elif res == max_tmp:
res_list.append(idx)
else:
continue
print(*res_list)
🔑