-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ-38
More file actions
31 lines (31 loc) · 934 Bytes
/
Q-38
File metadata and controls
31 lines (31 loc) · 934 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
#다르게 풀었지만,플로이드 워셜(모든 지점에서 다른 모든 지점까지의 최단경로 계산)사용하느 문제
#->모두 연결돼있으면 ok / 연결안돼있으면(거리=INF)둘이 비교 불가
n,m=map(int,input().split())
up=[[] for _ in range(n+1)]
down=[[] for _ in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
up[a].append(b)
down[b].append(a)
for j in range(1,n+1):
if len(down[a])>0:
down[b]=down[b]+down[a]
elif len(up[b])>0:
up[a]=up[a]+up[b]
for i in range(1,n+1):
result=[]
for val in up[i]:
if val not in result:
result.append(val)
up[i]=result
for i in range(1,n+1):
result=[]
for val in down[i]:
if val not in result:
result.append(val)
down[i]=result
res=0
for i in range(1,n+1):
if len(up[i])+len(down[i])==5:
res+=1
print(res)