AcWing 4859. 野生动物园
原题链接
简单
作者:
YAX_AC
,
2024-12-12 10:37:49
,
所有人可见
,
阅读 4
#include<bits/stdc++.h>
using namespace std;
const int N = 510;
int n,r,k,m;
int neighbor[N][N];
int main()
{
cin>>n>>r>>k;
while(r--)
{
int a,b;
cin>>a>>b;//相邻关系
neighbor[a][b] = neighbor[b][a] = 1;
}
cin>>m;
while(m--)
{
map<int,vector<int>> species;
for(int i = 1; i<=n; i++)
{
int x;cin>>x;
species[x].push_back(i);
}
if(species.size() > k) puts("Error: Too many species.");
else if(species.size() < k) puts("Error: Too few species.");
else
{
int st = 1;
for(auto it:species)
{
for(int i = 0; i<it.second.size(); i++)
for(int j = i+1; j<it.second.size(); j++)
{
if(neighbor[it.second[i]][it.second[j]])//相邻
{
st = 0;
break;
}
}
}
if(st) puts("Yes");
else puts("No");
}
}
return 0;
}