题目描述
分析:利用map存储不相容的物品,利用set存储查询的物品序列,完后遍历set
#include<unordered_map>
#include<unordered_set>
#include<iostream>
using namespace std;
typedef long long ll;
unordered_map<ll,unordered_set<ll>> um;
unordered_set<ll> us;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int m,n;
cin>>m>>n;
ll x,y;
while(m--){
cin>>x>>y;
um[x].insert(y);
um[y].insert(x);
}
int k;
while(n--){
cin>>k;
us.clear();
while(k--){
cin>>x;
us.insert(x);
}
for(auto i:us){
if(um.count(i)){
for(auto j:um[i]){
if(us.count(j)){
cout<<"No"<<endl;
goto loop;
}
}
}
}
cout<<"Yes"<<endl;
loop:;
}
return 0;
}