题意:给定一个由n个元素组成的序列f,一个由m个元素组成的序列b(n>=m),问是否唯一存在一个序列a[]使得
对任意的i,都有b[i] = f[a[i]]。
用两个map就可以轻松KO了。
AC代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define MAXN 1000000+10
#define MAXM 1010
#define eps 1e-8
#define LL long long
using namespace std;
int f[MAXN], b[MAXN];
map<int, int> fp;
map<int, int> id;
int main()
{
int n, m;
scanf("%d%d", &n, &m);
fp.clear(); id.clear();
for(int i = 1; i <= n; i++)
scanf("%d", &f[i]), fp[f[i]]++, id[f[i]] = i;
int sum = 0, tsum = 0;
for(int i = 1; i <= m; i++)
{
scanf("%d", &b[i]);
if(fp[b[i]] == 1)
sum++;
else if(fp[b[i]] > 1)
tsum++;
}
if(sum + tsum < m)
printf("Impossible\n");
else if(tsum > 0)
printf("Ambiguity\n");
else
{
printf("Possible\n");
int used = 0;
for(int i = 1; i <= m; i++)
{
if(fp[b[i]] == 1)
{
if(used > 0) printf(" ");
printf("%d", id[b[i]]);
used++;
}
}
printf("\n");
}
return 0;
}