time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
While Patrick wasgone shopping, Spongebob decided to play a little trick on his friend. Thenaughty Sponge browsed through Patrick's personal stuff and found a sequencea1, a2, ..., amof length m,consisting of integers from1 ton,not necessarily distinct. Then he picked some sequencef1, f2, ..., fnof length nand for each numberaigot numberbi = fai.To finish the prank he erased the initial sequence ai.
It's hard to expresshow sad Patrick was when he returned home from shopping! We will just say thatSpongebob immediately got really sorry about what he has done and he is nowtrying to restore the original sequence. Help him do this or determine thatthis is impossible.
Input
The first line of theinput contains two integersn andm(1 ≤ n, m ≤ 100 000) —the lengths of sequencesfiandbirespectively.
The second linecontains nintegers, determining sequencef1, f2, ..., fn(1 ≤ fi ≤ n).
The last linecontains mintegers, determining sequenceb1, b2, ..., bm(1 ≤ bi ≤ n).
Output
Print "Possible"if there is exactly one sequenceai,such thatbi = faifor all ifrom1tom.Then printmintegersa1, a2, ..., am.
If there are multiplesuitable sequencesai,print "Ambiguity".
If Spongebob has made a mistake in hiscalculations and no suitable sequenceaiexists, print "Impossible".
Examples
Input
3 3
3 2 1
1 2 3
Output
Possible
3 2 1
Input
3 3
1 1 1
1 1 1
Output
Ambiguity
Input
3 3
1 2 1
3 3 3
Output
Impossible
Note
In the first sample 3is replaced by1and vice versa, while2 never changes. Theanswer exists and is unique.
In the second sampleall numbers are replaced by1, so it is impossibleto unambiguously restore the original sequence.
In the third sample fi ≠ 3for all i,so no sequenceaitransforms into suchbiand we can say for sure that Spongebob has made a mistake.
题意:
有时间再写。
参考代码:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#define MYDD 110300
using namespace std;
int main() {
int n,m,val,A[MYDD],pos[MYDD],bol[MYDD],res[MYDD];
scanf("%d %d",&n,&m);
for(int i=1; i<=n; i++) {
scanf("%d",&val);
if (pos[val])
bol[val]=true;
else
pos[val]=i;
}
for(int i=1; i<=m; i++) {
scanf("%d",&A[i]);
if (!pos[A[i]])
return printf("Impossible\n"),0;
}
for(int i=1; i<=m; i++) {
val=A[i];
if (bol[val])
return printf("Ambiguity\n"),0;
res[i]=pos[val];
}
printf("Possible\n");
for(int i=1; i<=m; i++)
printf("%d ",res[i]);
puts("");
}