This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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')
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |