# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088740 | 2024-09-14T23:38:39 Z | Izzy | Zamjena (COCI18_zamjena) | C++14 | 0 ms | 0 KB |
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')