Advertisement
jusohatam

Untitled

Nov 4th, 2020
2,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. def solution(n, graph):
  2.     start = 0
  3.     end = n - 1
  4.  
  5.     def dfs(s):
  6.         visited = [0] * n
  7.  
  8.         def _dfs(s):
  9.             visited[s] = 1
  10.             for v in graph[s]:
  11.                 if not visited[v]:
  12.                     _dfs(v)
  13.         _dfs(s)
  14.         return visited
  15.  
  16.     d1 = dfs(start)[end]
  17.     d2 = dfs(end)[start]
  18.     return d1 == d2 == 1
  19.  
  20.  
  21. n = int(input())
  22. graph = [[] for _ in range(n)]
  23. for i in range(n-1):
  24.     tmp = input()
  25.     for j, c in enumerate(tmp, i+1):
  26.         if c == 'R':
  27.             graph[j].append(i)
  28.         else:
  29.             graph[i].append(j)
  30. if solution(n, graph):
  31.     print('NO')
  32. else:
  33.     print('YES')
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement