27 lines
No EOL
647 B
Python
27 lines
No EOL
647 B
Python
n = int(input())
|
|
edges = [input().strip() for _ in range(n - 1)]
|
|
R_in = [0] * n
|
|
R_out = [0] * n
|
|
B_in = [0] * n
|
|
B_out = [0] * n
|
|
for i in range(n - 1):
|
|
row = edges[i]
|
|
for j_idx, color in enumerate(row):
|
|
j = i + 1 + j_idx
|
|
if color == 'R':
|
|
R_out[i] += 1
|
|
R_in[j] += 1
|
|
else:
|
|
B_out[i] += 1
|
|
B_in[j] += 1
|
|
t_mixed_x2 = 0
|
|
s_in_out = 0
|
|
for v in range(n):
|
|
road_R = R_in[v] + R_out[v]
|
|
road_B = B_in[v] + B_out[v]
|
|
t_mixed_x2 += road_R * road_B
|
|
s_in_out += R_in[v] * B_out[v] + B_in[v] * R_out[v]
|
|
if t_mixed_x2 // 2 == s_in_out:
|
|
print("YES")
|
|
else:
|
|
print("NO") |