-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.py
75 lines (69 loc) · 1.77 KB
/
C.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from collections import Counter
# import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
test=int(input())
while test:
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
omap={}
posi={}
posb={}
omap2=Counter(b)
tr=True
omap3=Counter(c)
for i in range(n):
if a[i]!=b[i]:
if b[i] in omap:
omap[b[i]]+=1
else:
omap[b[i]]=1
if b[i] in posi:
posi[b[i]].append(i)
else:
posi[b[i]]=[i]
if b[i] in posb:
posb[b[i]].append(i)
else:
posb[b[i]]=[i]
#print(omap)
for k,v in omap.items():
if k in omap3:
if omap[k]>omap3[k]:
tr=False
break
else:
tr=False
break
if tr:
li=[]
tr1=True
for i in range(m):
if c[i] in posi:
li.append(posi[c[i]].pop(0))
if len(posi[c[i]])==0:
del posi[c[i]]
elif c[i] in posb:
li.append(posb[c[i]][0])
elif len(posi)>0:
for k,v in posi.items():
li.append(v[0])
break
elif i!=m-1:
if c[m-1] in posb:
li.append(posb[c[m-1]][0])
else:
tr1=False
break
if tr1:
print("Yes")
for i in li:
print(i+1,end=" ")
print()
else:
print("No")
else:
print("No")
test-=1