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 sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n and for each number ai got number bi = fai. To finish the prank he erased the initial sequence ai.

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 integers n and m (1 ≤ n, m ≤ 100 000) — the lengths of sequences fi and bi respectively.

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

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

Output

Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am.

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

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

Sample Input

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

Hint

In the first sample 3 is replaced by 1 and vice versa, while 2 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 all i, so no sequence ai transforms into such bi and we can say for sure that Spongebob has made a mistake.

题意:给你数组f[]和数组b[]问你是否存在数组a[]使得bi==fai;

题解:三种情况1、数组b中的数字数组f中没有 则输出Impossible     2、数组b中的数字在数组f中重复出现且数组b中的数字都在数组f中输出Ambiguity      3、数组b中的数字都在数组f中且无重复输出Possible以及数组a[]

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define LL long long
#define MAX 100100
using namespace std;
int b[MAX],f[MAX];
int a[MAX],vis[MAX];
int main()
{
int n,m,i,j,ans;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(vis,0,sizeof(vis));
for(i=1;i<=n;i++)
{
scanf("%d",&ans);
f[ans]=i;
vis[ans]++;
}
for(i=1;i<=m;i++)
scanf("%d",&b[i]);
int flag=0;
int Flag=0;
for(i=1;i<=m;i++)
{
if(vis[b[i]]==0)
{
flag=1;
break;
}
if(vis[b[i]]>1)
Flag=1;
}
if(flag)
{
printf("Impossible\n");
continue;
}
if(Flag)
{
printf("Ambiguity\n");
continue;
}
for(i=1;i<=m;i++)
a[i]=f[b[i]];
printf("Possible\n");
for(i=1;i<m;i++)
printf("%d ",a[i]);
printf("%d\n",a[m]);
}
return 0;
}

  

Codeforces Round #332 (Div. 二) B. Spongebob and Joke的更多相关文章

  1. Codeforces Round #332 (Div. 2) B. Spongebob and Joke 水题

    B. Spongebob and Joke Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599 ...

  2. Codeforces Round #332 (Div. 2)_B. Spongebob and Joke

    B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #332 (Div. 2)B. Spongebob and Joke

    B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. Codeforces Round #332 (Div. 2) B. Spongebob and Joke 模拟

    B. Spongebob and Joke     While Patrick was gone shopping, Spongebob decided to play a little trick ...

  5. Codeforces Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举

    D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  6. Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)

    http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...

  7. Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学

    D. Spongebob and Squares   Spongebob is already tired trying to reason his weird actions and calcula ...

  8. Codeforces Round #332 (Div. 2)

    水 A - Patrick and Shopping #include <bits/stdc++.h> using namespace std; int main(void) { int ...

  9. Codeforces Round #332 (Div. 2) C. Day at the Beach 线段树

    C. Day at the Beach Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/p ...

随机推荐

  1. 深入理解Java虚拟机

    1. Java内存模型,Java内存管理,Java堆和栈,垃圾回收 http://nibnait.com/6f8dd084-about-Java-Virtual-Machine/ 2. JVM性能调优 ...

  2. 进程间通信的WM_COPYDATA的使用

    http://blog.csdn.net/ao929929fei/article/details/6316174 接收数据的一方 ON_WM_COPYDATA() afx_msg BOOL OnCop ...

  3. Android Monkey测试

    Monkey测试1——Monkey的使用 原文地址: http://www.douban.com/note/257029872/ (转自豆瓣,版权属于豆瓣及豆瓣网友,如有冒犯请见谅并联系我们) Mon ...

  4. 设置图片Alpha

    Drawable ico = getResources().getDrawable(R.drawable.search_box);                       mSearchLayou ...

  5. 函数buf_page_hash_get_low

    /******************************************************************//** Returns the control block of ...

  6. SQL Server索引怎么用

    什么是索引 拿汉语字典的目录页(索引)打比方:正如汉语字典中的汉字按页存放一样,SQL Server中的数据记录也是按页存放的,每页容量一般为4K .为了加快查找的速度,汉语字(词)典一般都有按拼音. ...

  7. Lost connection to MySQL server at 'reading initial communication packet' 错误解决

    Lost connection to MySQL server at 'reading initial communication packet' 错误解决 上次解决了这个问题,今天又碰到,突然失忆, ...

  8. 转:ASP.NET MVC中Unobtrusive Ajax的妙用

    Unobtrusive Javascript有三层含义:一是在HTML代码中不会随意的插入Javsscript代码,只在标签中加一些额外的属性值,然后被引用的脚本文件识别和处理:二是通过脚本文件所增加 ...

  9. Make AngularJS $http service behave like jQuery.ajax()(转)

    There is much confusion among newcomers to AngularJS as to why the $http service shorthand functions ...

  10. B树索引和位图索引的区别!

    B树索引主键和唯一性约束字段的B树索引,效率几乎和海量数据没有关系. 键值重复率低的字段比较适合使用B树索引. 位图索引键值重复率高的字段比较适合使用位图索引.count.and.or.in这些特定的 ...