Home (Python)[백준] 친구_1058
Post
Cancel

(Python)[백준] 친구_1058

1058번: 친구

풀이


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# floydwarshall

import sys

n = int(sys.stdin.readline())
graph = [list(sys.stdin.readline().strip()) for _ in range(n)]

f = [[0] * n for _ in range(n)]

for k in range(n):
  for i in range(n):
    for j in range(n):
      if i == j:
        continue
      if graph[i][j] == 'Y' or (graph[i][k] == 'Y' and graph[k][j] =='Y'):
        f[i][j] = 1
ans = 0
for row in f:
  ans = max(ans,sum(row))
print(ans)
This post is licensed under CC BY 4.0 by the author.