답안 #995375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995375 2024-06-09T00:48:26 Z rsinventor Zamjena (COCI18_zamjena) Python 3
70 / 70
126 ms 21576 KB
n = eval(input());
a = input().split(" ")
b = input().split(" ")

visited = {}
adj = {}
for i in range(n):
    visited[a[i]] = False
    visited[b[i]] = False
    if(a[i] not in adj.keys()):
        adj[a[i]] = []
    if(b[i] not in adj.keys()):
        adj[b[i]] = []
    adj[a[i]].append(b[i])
    adj[b[i]].append(a[i])
    if a[i].isnumeric() and b[i].isnumeric() and a[i]!=b[i]:
        flag = False
        break

flag = True;
to_visit = [];
for i in range(n):
    if not visited[a[i]]:
        to_visit.append(a[i])
        visited[a[i]] = True;
        cnt = set()
        if(a[i].isnumeric()):
            cnt.add(a[i])
        while(len(to_visit)>0):
            curr = to_visit[0]
            to_visit.pop(0)
            for ap in adj[curr]:
                if not visited[ap]:
                    visited[ap] = True
                    to_visit.append(ap)
                    if(ap.isnumeric()):
                        cnt.add(ap)
        if(len(cnt)>1):
            flag = False
            break



if flag:
    print("DA")
else:
    print("NE")
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 2908 KB Output is correct
2 Correct 11 ms 2908 KB Output is correct
3 Correct 11 ms 2944 KB Output is correct
4 Correct 11 ms 2908 KB Output is correct
5 Correct 11 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 2908 KB Output is correct
2 Correct 13 ms 2968 KB Output is correct
3 Correct 12 ms 3032 KB Output is correct
4 Correct 11 ms 3032 KB Output is correct
5 Correct 11 ms 2976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 2908 KB Output is correct
2 Correct 11 ms 2900 KB Output is correct
3 Correct 10 ms 3056 KB Output is correct
4 Correct 11 ms 3092 KB Output is correct
5 Correct 11 ms 2908 KB Output is correct
6 Correct 11 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 3348 KB Output is correct
2 Correct 16 ms 3300 KB Output is correct
3 Correct 17 ms 3932 KB Output is correct
4 Correct 16 ms 3928 KB Output is correct
5 Correct 18 ms 4076 KB Output is correct
6 Correct 18 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 6012 KB Output is correct
2 Correct 51 ms 8728 KB Output is correct
3 Correct 53 ms 13096 KB Output is correct
4 Correct 72 ms 14484 KB Output is correct
5 Correct 126 ms 21576 KB Output is correct
6 Correct 102 ms 14664 KB Output is correct