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. jQuery $.post $.ajax用法

    jQuery $.post $.ajax用法 jQuery.post( url, [data], [callback], [type] ) :使用POST方式来进行异步请求 参数: url (Stri ...

  2. VS2010中如果忘记函数所在的头文件或者忘记函数的输入输出参数类型怎么办?

    先随便找一个熟悉的函数,右击-转到定义,然后写出目标函数,右击-转到定义

  3. IE css expression(表达式)

    很多时候我们需要对IE6的bug写一些hack,如max-height,absolute元素高度100%等. css里面的 expression(表达式)和js里面的差不多,如: 获取当前元素的高度: ...

  4. bzoj4154

    一开始读错题,各种不会做,后来发现染色只是染孩子…… 那不就简单了吗……注意这题是允许离线的 染色如果没有距离限制,它就是个dfs序 距离限制怎么做呢?我们考虑扩展一维变成二维的问题,将每个点变为二维 ...

  5. NALU(NAL单元)

    一 NALU类型    标识NAL单元中的RBSP数据类型,其中,nal_unit_type为1, 2, 3, 4, 5及12的NAL单元称为VCL的NAL单元,其他类型的NAL单元为非VCL的NAL ...

  6. Python easy_install

    系统中有高版本的Python, 直接pip3 install ipcalc安装,都是装到高版本的Python 系统默认的Python是2.7.6,现在想装到默认版本中,可以使用easy_install ...

  7. IIS部署网站

  8. MyBatis 物理分页

    MyBatis使用RowBounds实现的分页是逻辑分页,也就是先把数据记录全部查询出来,然在再根据offset和limit截断记录返回 为了在数据库层面上实现物理分页,又不改变原来MyBatis的函 ...

  9. 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(5)

    数据操作与REST API(Data manipulation with REST API) ElasticSearch REST API可用于各种任务.多亏了它,我们可以管理索引,更改实例参数,检查 ...

  10. poj 3311 Hie with the Pie

    floyd,旅游问题每个点都要到,可重复,最后回来,dp http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS   Me ...