题目
题意:
动物园的动物数小于等于区域数,判断放置的方案能不能满足相邻的区域没有同一种动物。
tips:模拟
#include<iostream>
#include<vector>
#include<set>
#include<map>
using namespace std;
int main() {
int n,r,k;
cin>>n>>r>>k;
map<int,vector<int>>ans;
for(int i=0; i<r; ++i) {
int a,b;
cin>>a>>b;
ans[a].push_back(b);
ans[b].push_back(a);
}
int m;
cin>>m;
for(int i=0; i<m; ++i) {
int a,b;
set<int> count;
vector<int> temp(n+1,0);
for(int t=1; t<=n; ++t) {
cin>>temp[t];
count.insert(temp[t]);
}
if(count.size()<k)
cout<<"Error: Too few species."<<endl;
else if(count.size()>k)
cout<<"Error: Too many species."<<endl;
else {
int flag=0;
for(int t=1; t<=n; ++t) {
for(int j=0;j<ans[t].size();++j)
if(temp[ans[t][j]]==temp[t])
{
flag=1;
break;
}
}
if(flag)
cout<<"No"<<endl;
else if(!flag)cout<<"Yes"<<endl;
}
}
return 0;
}