def isNumber(a):
abc = list("0123456789")
if a[0] in abc:
return True
return False
def traverse(start):
queue = [start]
num = None
while queue:
a = queue.pop(0)
if type(a) == int:
if num == None:
num = a
elif num != a:
return False
visited[toIndex[a]] = True
for i in adj[a]:
if not visited[toIndex[i]]:
visited[toIndex[i]] = False
queue.append(i)
return True
n = int(input())
arr1 = input().split(' ')
arr2 = input().split(' ')
adj = {}
works = True
for i in range(n):
if isNumber(arr1[i]) and isNumber(arr2[i]) and arr1[i] != arr2[i]:
print('NE')
works = False
break
if isNumber(arr1[i]):
arr1[i] = int(arr1[i])
if isNumber(arr2[i]):
arr2[i] = int(arr2[i])
if arr1[i] != arr2[i] and arr1[i] in adj:
adj[arr1[i]].add(arr2[i])
elif arr1[i] != arr2[i] and arr1[i] not in adj:
adj[arr1[i]] = set([arr2[i]])
if arr1[i] != arr2[i] and arr2[i] in adj:
adj[arr2[i]].add(arr1[i])
elif arr1[i] != arr2[i] and arr2[i] not in adj:
adj[arr2[i]] = set([arr1[i]])
toIndex = {}
fromIndex = {}
visited = []
if works:
visited = [False for i in range(len(adj))]
temp = 0
for i in adj:
toIndex[i] = temp
fromIndex[temp] = i
temp += 1
for i in range(len(visited)):
if not visited[i]:
works = traverse(fromIndex[i])
if not works:
print('NE')
break
if works:
print('DA')
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3164 KB |
Output is correct |
2 |
Correct |
10 ms |
3180 KB |
Output is correct |
3 |
Correct |
10 ms |
2976 KB |
Output is correct |
4 |
Correct |
10 ms |
2980 KB |
Output is correct |
5 |
Correct |
10 ms |
3012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3164 KB |
Output is correct |
2 |
Correct |
11 ms |
3152 KB |
Output is correct |
3 |
Correct |
11 ms |
3164 KB |
Output is correct |
4 |
Correct |
12 ms |
3432 KB |
Output is correct |
5 |
Correct |
12 ms |
3008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3164 KB |
Output is correct |
2 |
Correct |
11 ms |
3164 KB |
Output is correct |
3 |
Correct |
11 ms |
3180 KB |
Output is correct |
4 |
Correct |
11 ms |
3164 KB |
Output is correct |
5 |
Correct |
11 ms |
3164 KB |
Output is correct |
6 |
Correct |
11 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
3420 KB |
Output is correct |
2 |
Correct |
14 ms |
3420 KB |
Output is correct |
3 |
Correct |
21 ms |
4632 KB |
Output is correct |
4 |
Correct |
21 ms |
4700 KB |
Output is correct |
5 |
Correct |
22 ms |
4636 KB |
Output is correct |
6 |
Correct |
28 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
7872 KB |
Output is correct |
2 |
Correct |
91 ms |
12700 KB |
Output is correct |
3 |
Correct |
115 ms |
20668 KB |
Output is correct |
4 |
Correct |
164 ms |
21648 KB |
Output is correct |
5 |
Correct |
269 ms |
35580 KB |
Output is correct |
6 |
Correct |
271 ms |
23268 KB |
Output is correct |