forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (28 loc) · 831 Bytes
/
main.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
# Authored by : gkgg123
# Co-authored by : -
# Link : https://www.acmicpc.net/source/share/a369084903d348d2966ab752ccb745ec
import sys
def input():
return sys.stdin.readline().rstrip()
def dfs(idx):
global N
visited = [ True for _ in range(N) ]
visited[idx] = False
stack = [ (idx, 0) ]
total = 0
while stack:
curent_x, p_cnt = stack.pop()
for either_x in range(N):
if arr[curent_x][either_x] == 'Y':
if visited[either_x] and p_cnt <= 1:
visited[either_x] = False
stack.append((either_x, p_cnt+1))
total += 1
return total
N = int(input())
arr = [list(input()) for _ in range(N)]
max_number = 0
for i in range(N):
cu_cnt = dfs(i)
max_number = max(max_number,cu_cnt)
print(max_number)