CF599B.Spongebob and Joke

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 sequence a1,a2,...,ama_{1},a_{2},...,a_{m} of length mm , consisting of integers from 11 to nn , not necessarily distinct. Then he picked some sequence f1,f2,...,fnf_{1},f_{2},...,f_{n} of length nn and for each number aia_{i} got number bi=faib_{i}=f_{ai} . To finish the prank he erased the initial sequence aia_{i} .

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.

输入格式

The first line of the input contains two integers nn and mm ( 1<=n,m<=1000001<=n,m<=100000 ) — the lengths of sequences fif_{i} and bib_{i} respectively.

The second line contains nn integers, determining sequence f1,f2,...,fnf_{1},f_{2},...,f_{n} ( 1<=fi<=n1<=f_{i}<=n ).

The last line contains mm integers, determining sequence b1,b2,...,bmb_{1},b_{2},...,b_{m} (1<=bi<=n)(1<=b_{i}<=n) .

输出格式

Print "Possible" if there is exactly one sequence aia_{i} , such that bi=faib_{i}=f_{ai} for all ii from 11 to mm . Then print mm integers a1,a2,...,ama_{1},a_{2},...,a_{m} .

If there are multiple suitable sequences aia_{i} , print "Ambiguity".

If Spongebob has made a mistake in his calculations and no suitable sequence aia_{i} exists, print "Impossible".

输入输出样例

  • 输入#1

    3 3
    3 2 1
    1 2 3
    

    输出#1

    Possible
    3 2 1 
    
  • 输入#2

    3 3
    1 1 1
    1 1 1
    

    输出#2

    Ambiguity
    
  • 输入#3

    3 3
    1 2 1
    3 3 3
    

    输出#3

    Impossible
    

说明/提示

In the first sample 33 is replaced by 11 and vice versa, while 22 never changes. The answer exists and is unique.

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

In the third sample fi3f_{i}≠3 for all ii , so no sequence aia_{i} transforms into such bib_{i} and we can say for sure that Spongebob has made a mistake.

首页