题目:https://pintia.cn/problem-sets/994805260223102976/problems/1038429484026175488
代码
#include<cstdio>#include<iostream>#include<map>#include<vector>using namespace std;map<int, vector<int> > mp;void new_and_append(int temp_a, int temp_b){if(mp.find(temp_a) == mp.end()){vector<int> temp_vec;temp_vec.push_back(temp_b);mp[temp_a] = temp_vec;} else {mp[temp_a].push_back(temp_b);}}int main(){int n, m;int temp_a, temp_b;scanf("%d %d", &n, &m);for(int i = 0; i < n; i++){scanf("%d%d", &temp_a, &temp_b);new_and_append(temp_a, temp_b);new_and_append(temp_b, temp_a);}int turns, temp_int;for(int i = 0; i < m; i++){scanf("%d", &turns);int flag = 0;vector<bool> hash(100010, false);for(int j = 0; j < turns; j++){scanf("%d", &temp_int);hash[temp_int] = true;for(int k = 0; k < mp[temp_int].size(); k++){if(hash[mp[temp_int][k]]){flag = 1;break;}}}flag == 0 ? printf("Yes\n") : printf("No\n");}}
