Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def solution(n, graph):
- start = 0
- end = n - 1
- def dfs(s):
- visited = [0] * n
- def _dfs(s):
- visited[s] = 1
- for v in graph[s]:
- if not visited[v]:
- _dfs(v)
- _dfs(s)
- return visited
- d1 = dfs(start)[end]
- d2 = dfs(end)[start]
- return d1 == d2 == 1
- n = int(input())
- graph = [[] for _ in range(n)]
- for i in range(n-1):
- tmp = input()
- for j, c in enumerate(tmp, i+1):
- if c == 'R':
- graph[j].append(i)
- else:
- graph[i].append(j)
- if solution(n, graph):
- print('NO')
- else:
- print('YES')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement