-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOJ_1325_효율적인해킹_RE.py
54 lines (39 loc) · 1.08 KB
/
BOJ_1325_효율적인해킹_RE.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
from collections import deque
import sys
input = lambda : sys.stdin.readline().rstrip()
print = lambda x : sys.stdout.write(str(x))
N,M = map(int, input().split())
graph = [[] for _ in range(N+1)]
counts = [0] * (N+1) # index: Node Num, Value: Infection Total Count
for i in range(M):
a,b = map(int,input().split())
# Directed Graph
#if not a==b:
graph[b].append(a)
def bfs(start):
# start like '2:Node Number'
queue = deque([start])
visited = [False] * (N+1)
res = []
while queue:
for _ in range(len(queue)):
x = queue.popleft()
if not visited[x]:
res.append(x)
visited[x] = True
for i in range(len(graph[x])):
if not visited[graph[x][i]]:
queue.append(graph[x][i])
return len(res)
for i in range(1,N+1):
counts[i] = bfs(i)
max_count = max(counts)
res = []
for i in range(len(counts)):
if counts[i] == max_count:
res.append(i)
res.sort()
answer = ""
for i in res:
answer += str(i) + " "
print(answer.rstrip())