-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOJ_2458.py
51 lines (45 loc) · 1.22 KB
/
BOJ_2458.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
# import sys
# input = sys.stdin.readline
#
# n, m = map(int, input().split())
# compare = [[False for _ in range(n+1)] for _ in range(n+1)]
# d = [[False for _ in range(n+1)] for _ in range(n+1)]
#
# for _ in range(m):
# s, e = map(int, input().split())
# compare[s][e] = True
# compare[e][s] = True
# d[s][e] = True
#
# for k in range(1, n+1):
# compare[k][k] = True
# for i in range(1, n+1):
# for j in range(1, n+1):
# if d[i][k] and d[k][j]:
# compare[i][j] = True
# compare[j][i] = True
#
# ans = 0
# for i in range(1, n+1):
# if compare[i][1:n+1].count(False) == 0:
# ans += 1
# print(ans)
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
compare = [[False for _ in range(n+1)] for _ in range(n+1)]
for _ in range(m):
s, e = map(int, input().split())
compare[s][e] = True
for k in range(1, n+1):
for i in range(1, n+1):
for j in range(1, n+1):
if compare[i][k] and compare[k][j]:
compare[i][j] = True
ans = [0 for _ in range(n+1)]
for i in range(1, n+1):
for j in range(1, n+1):
if compare[i][j]:
ans[i] += 1
ans[j] += 1
print(ans.count(n-1))