1090 危險品裝箱(25 分)
阿新 • • 發佈:2018-12-09
1 #include<iostream> 2 #include<map> 3 #include<vector> 4 using namespace std; 5 map<string, vector<string>> m1; 6 map<string, int> m2; 7 vector<string> v1; 8 int main() 9 { 10 int n, m; 11 cin >> n >> m; 12 for(int i = 0; i < n; i++) {13 string a, b; 14 cin >> a >> b; 15 m1[a].push_back(b); 16 m1[b].push_back(a); 17 } 18 while(m--) { 19 int k; 20 cin >> k; 21 v1.clear(); 22 m2.clear(); 23 int flag = 0; 24 while(k--) { 25 stringa; 26 cin >> a; 27 m2[a] = 1; 28 v1.push_back(a); 29 } 30 for(int i = 0; i < v1.size(); i++) { 31 for(int j = 0; j < m1[v1[i]].size(); j++) { 32 if(m2[m1[v1[i]][j]] == 1) { 33 flag = 1; 34 break; 35 } 36 } 37 } 38 if(flag == 1) { 39 cout << "No" << endl; 40 } else { 41 cout << "Yes" << endl; 42 } 43 } 44 }