-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1325.py
More file actions
36 lines (31 loc) · 739 Bytes
/
1325.py
File metadata and controls
36 lines (31 loc) · 739 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
#20250804
#1325 효율적인 해킹
#BFS, 그래프
#백준에서 python3은 시간초과, pypy3은 통과
import sys
from collections import deque
input=sys.stdin.readline
n,m=map(int,input().split())
a=[[] for i in range(n+1)]
answer=[0]*(n+1)
def BFS(v):
visited=[False]*(n+1)
queue=deque()
queue.append(v)
visited[v]=True
while queue:
now=queue.popleft()
for i in a[now]:
if not visited[i]:
visited[i]=True
answer[i]+=1
queue.append(i)
for i in range(m):
s,e=map(int,input().split())
a[s].append(e)
for i in range(1,n+1):
BFS(i)
maxVal=max(answer)
for i in range(1,n+1):
if maxVal==answer[i]:
print(i,end=' ')