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. fiddler for mac

    Fiddler 是一免费的web调试工具.并且兼容所有浏览器.系统和平台. Fiddler 是基于微软的 .Net 技术开发的,没办法直接在 Mac/Linux 下使用.本文介绍一些替代方案(这些方案 ...

  2. 沉浸式学 Git

    沉浸式学 Git cover — contents — about 目录 设置 再谈设置 创建项目 检查状态 做更改 暂存更改 暂存与提交 提交更改 更改而非文件 历史 别名 获得旧版本 给版本打标签 ...

  3. 函数buf_page_create

    /********************************************************************//** Initializes a page to the ...

  4. UVa 11609 (计数 公式推导) Teams

    n个人里选k个人有C(n, k)中方法,再从里面选一人当队长,有k中方法. 所以答案就是 第一步的变形只要按照组合数公式展开把n提出来即可. #include <cstdio> typed ...

  5. BZOJ2626: JZPFAR

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2626 题解:裸K-Dtree,最大值?自己yy一下估价函数就好了. 两题居然是同一个错误,真是 ...

  6. UVA 11374 Airport Express(最短路)

    最短路. 把题目抽象一下:已知一张图,边上的权值表示长度.现在又有一些边,只能从其中选一条加入原图,使起点->终点的距离最小. 当加上一条边a->b,如果这条边更新了最短路,那么起点st- ...

  7. 笨笨-歌词伴侣V1.2(酷狗KRC转LRC,LRC歌词批量下载)

      最近由于某些热心博友在我CSDN博客上使用了我的软件,提出了一些建议,看到自己的成果有人使用并且提出了一些建议,焉有不高兴之理!刚好碰上最近研究UI界面,有了一个初步的框架,就顺手将歌词相关功能集 ...

  8. HDU 1233 还是畅通工程(最小生成树,prim)

    题意:中文题目 思路:prim实现,因为有n*(n-1)/2条边,已经是饱和的边了,prim比较合适. (1)将点1置为浏览过,点1可以到达其他每个点,所以用low[i]数组记录下目前到达i点的最小长 ...

  9. atoi&itoa

    char* itoa(int num,char*str,int radix) {/*索引表*/ char index[]="0123456789ABCDEFGHIJKLMNOPQRSTUVW ...

  10. LeetCode: Sqrt

    Title: Implement int sqrt(int x). Compute and return the square root of x. 思路:这个平方根肯定是在[1,x]之间,所以在这个 ...