Spongebob and Joke(记录数据地址)

来源:互联网 发布:php json decode 编辑:程序博客网 时间:2024/06/07 20:22

                         Spongebob and Joke

Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

SubmitStatus

Description

While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequencea1, a2, ..., am of lengthm, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequencef1, f2, ..., fn of lengthn and for each number ai got number bi = fai. To finish the prank he erased the initial sequenceai.

It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible.

Input

The first line of the input contains two integersn andm (1 ≤ n, m ≤ 100 000) — the lengths of sequencesfi andbi respectively.

The second line contains n integers, determining sequencef1, f2, ..., fn (1 ≤ fi ≤ n).

The last line contains m integers, determining sequenceb1, b2, ..., bm(1 ≤ bi ≤ n).

Output

Print "Possible" if there is exactly one sequenceai, such thatbi = fai for alli from 1 tom. Then print m integersa1, a2, ..., am.

If there are multiple suitable sequences ai, print "Ambiguity".

If Spongebob has made a mistake in his calculations and no suitable sequenceai exists, print "Impossible".

Sample Input

Input
3 33 2 11 2 3
Output
Possible3 2 1 
Input
3 31 1 11 1 1
Output
Ambiguity
Input
3 31 2 13 3 3
Output
Impossible

Hint

In the first sample 3 is replaced by1 and vice versa, while2 never changes. The answer exists and is unique.

In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence.

In the third sample fi ≠ 3 for alli, so no sequenceai transforms into suchbi and we can say for sure that Spongebob has made a mistake.

给出两个集合,f与d,问是否存在另外一个集合a,使,f[a[i]]=b[i],这两天自学容器,初次试手

#include<stdio.h>#include<algorithm>#include<iostream>#include<map>using namespace std;int f[100005],b[100005];int main(){map<int,int>k1;//定义map容器map<int,int>k2;k1.clear();k2.clear();int n,m,x;int sum=0,num=0;scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%d",&f[i]);k1[f[i]]++;//键值k2[f[i]]=i;}//记录位置for(int i=1;i<=m;i++){scanf("%d",&b[i]);if(k1[b[i]]==1)sum++;if(k2[b[i]]==0)num++;}if(num!=0)printf("Impossible\n");if(num==0&&sum<m)printf("Ambiguity\n");if(sum==m){printf("Possible\n");for(int i=1;i<=m;i++){if(k1[b[i]]==1)printf("%d ",k2[b[i]]);}printf("\n");}}



0 0
原创粉丝点击