#include <bits/stdc++.h>
typedef long long ll ;
using namespace std ;
const int maxn = 5e2 + 10 ;
const int inf = 0x3f3f3f3f ;
map<int , set<int> > mp ;
int a[maxn] ;
void deal(){
int n , r , k ;
cin >> n >> r >> k ;
for(int i = 0 ; i < r ; i++){
int u , v ;
cin >> u >> v ;
mp[u].insert(v) ;
mp[v].insert(u) ;
}
int m ; cin >> m ;
for(int i = 0 ; i < m ; i++){
set<int > st ;
for(int j = 1 ; j <= n ; j++){
cin >> a[j] ;
st.insert(a[j]) ;
}
if(st.size() > k){
cout << "Error: Too many species.\n" ;
continue ;
}else if(st.size() < k){
cout << "Error: Too few species.\n" ;
continue ;
}
int f = 1 ;
for(int j = 0 ; j < n ; j++){
for(auto &x : mp[j]){
if(a[j] == a[x]){
f = 0 ;
break ;
}
}
if(!f)break ;
}
if(f)cout << "Yes\n" ;
else cout << "No\n" ;
}
}
int main(){
deal() ;
return 0 ;
}
pat甲级1170
C++程序:处理物种集合与图的关系,
于 2023-03-08 16:49:43 首次发布
该程序读取边的集合构建图,然后处理一系列物种集合,检查是否满足特定条件。如果物种集合超过给定限制或少于限制,程序会输出错误信息;否则,它会检查物种在图中是否存在自环,从而决定输出Yes或No。
208

被折叠的 条评论
为什么被折叠?



