When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we might get ourselves in serious trouble. For example, oxidizing agent (氧化剂) must not be packed with flammable liquid (易燃液体), or it can cause explosion.

Now you are given a long list of incompatible goods, and several lists of goods to be shipped. You are supposed to tell if all the goods in a list can be packed into the same container.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers: N (≤10​4​​), the number of pairs of incompatible goods, and M (≤100), the number of lists of goods to be shipped.

Then two blocks follow. The first block contains N pairs of incompatible goods, each pair occupies a line; and the second one contains M lists of goods to be shipped, each list occupies a line in the following format:

K G[1] G[2] ... G[K]

where K (≤1,000) is the number of goods and G[i]'s are the IDs of the goods. To make it simple, each good is represented by a 5-digit ID number. All the numbers in a line are separated by spaces.

Output Specification:

For each shipping list, print in a line Yes if there are no incompatible goods in the list, or No if not.

Sample Input:

6 3
20001 20002
20003 20004
20005 20006
20003 20001
20005 20004
20004 20006
4 00001 20004 00002 20003
5 98823 20002 20003 20006 10010
3 12345 67890 23333

Sample Output:

No
Yes
Yes

#include<iostream>
#include<vector>
#include<map>
using namespace std; int main(){
map<string,vector<string> > m1;
map<string,int> m2;
vector<string> v;
int n,m;
cin >> n >> m;
string a,b;
while(n--){
cin >> a >> b;
m1[a].push_back(b);
m1[b].push_back(a);
}
int k;
while(m--){
cin >> k;
m2.clear();
v.clear();
bool flag = ;
while(k--){
cin >> a;
v.push_back(a);
m2[a] = ;
}
for(int i = ; i < v.size(); i++){
for(int j = ; j < m1[v[i]].size(); j++){
if(m2[m1[v[i]][j]] == ){
flag = ;
break;
}
}
}
if(flag) cout << "No" <<endl;
else cout << "Yes" <<endl;
}
return ;
}

1149 Dangerous Goods Packaging (25 分)的更多相关文章

  1. pat 1149 Dangerous Goods Packaging(25 分)

    1149 Dangerous Goods Packaging(25 分) When shipping goods with containers, we have to be careful not ...

  2. 1149 Dangerous Goods Packaging

    When shipping goods with containers, we have to be careful not to pack some incompatible goods into ...

  3. PAT_A1149#Dangerous Goods Packaging

    Source: PAT A1149 Dangerous Goods Packaging (25 分) Description: When shipping goods with containers, ...

  4. PAT A1149 Dangerous Goods Packaging (25 分)——set查找

    When shipping goods with containers, we have to be careful not to pack some incompatible goods into ...

  5. PTA - - 06-图1 列出连通集 (25分)

    06-图1 列出连通集   (25分) 给定一个有NN个顶点和EE条边的无向图,请用DFS和BFS分别列出其所有的连通集.假设顶点从0到N-1N−1编号.进行搜索时,假设我们总是从编号最小的顶点出发, ...

  6. 中国大学MOOC-陈越、何钦铭-数据结构-2015秋 01-复杂度2 Maximum Subsequence Sum (25分)

    01-复杂度2 Maximum Subsequence Sum   (25分) Given a sequence of K integers { N​1​​,N​2​​, ..., N​K​​ }. ...

  7. PTA 字符串关键字的散列映射(25 分)

    7-17 字符串关键字的散列映射(25 分) 给定一系列由大写英文字母组成的字符串关键字和素数P,用移位法定义的散列函数H(Key)将关键字Key中的最后3个字符映射为整数,每个字符占5位:再用除留余 ...

  8. PTA 旅游规划(25 分)

    7-10 旅游规划(25 分) 有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路费.现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径.如果有若干条 ...

  9. L2-006 树的遍历 (25 分) (根据后序遍历与中序遍历建二叉树)

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805069361299456 L2-006 树的遍历 (25 分 ...

随机推荐

  1. SQL 数据排重,去掉重复数据 有用

    .最大的错误:    在对数据排重的时候,首先想到的就是Distinct,虽然这很管用,但多数场合下不适用,因为通常排重后还要做进一步处理,比如对编号排重后要按日期统计等. 无法排重的Group by ...

  2. SQL数据库游标

    这个文档几乎包含了oracle游标使用的方方面面,全部通过了测试 -- 声明游标:CURSOR cursor_name IS select_statement --For 循环游标--(1)定义游标- ...

  3. PHP加密与解密

    password_hash ( string $password , integer $algo [, array $options ] ) 加密,生成60位得字符串 $algo:一个用来在散列密码时 ...

  4. 当鼠标悬停在链接上,或者点击过的链接,颜色会被设置为 #2a6496。同时,会呈现一条下划线。点击过的链接,会呈现一个颜色码为 #333 的细的虚线轮廓。另一条规则是设置轮廓为 5 像素宽,且对于基于 webkit 浏览器有一个 -webkit-focus-ring-color 的浏览器扩展。轮廓偏移设置为 -2 像素

    a:hover, a:focus { color: #2a6496; text-decoration: underline; } a:focus { outline: thin dotted #333 ...

  5. Monkey基础命令

    最近一直在看关于自动化测试的文章和工具,这是之前学习monkey的一些知识,想总结一下,方便以后查看,当然也可以提供一些参考.monkey 适合做压力测试,我们可以发送命令让它自己运行,并且指定运行动 ...

  6. On the nightmare that is JSON Dates. Plus, JSON.NET and ASP.NET Web API

    Ints are easy. Strings are mostly easy. Dates? A nightmare. They always will be. There's different c ...

  7. (转)基于MVC4+EasyUI的Web开发框架形成之旅--界面控件的使用

    原文地址:http://www.cnblogs.com/wuhuacong/p/3317223.html 在前面介绍了两篇关于我的基于MVC4+EasyUI技术的Web开发框架的随笔,本篇继续介绍其中 ...

  8. ASP.NET MVC4 学习记录

    之前在学习Artech的<ASP.NET MVC4框架揭秘>一书,学习过程中画了ASP.NET MVC4框架的草图,方便记忆.

  9. c# 实现点击下载功能

    转自百度知道 private void DownLoad(string strName, string strPath) { string fileName = strName;//客户端保存的文件名 ...

  10. html manifest 离线配置

    HTML5 引入了应用程序缓存,这意味着 web 应用可进行缓存,并可在没有因特网连接时进行访问. 应用程序缓存为应用带来三个优势: 离线浏览 - 用户可在应用离线时使用它们 速度 - 已缓存资源加载 ...