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 = 0;while(k--){cin >> a;v.push_back(a);m2[a] = 1;}for(int i = 0; i < v.size(); i++){for(int j = 0; j < m1[v[i]].size(); j++){if(m2[m1[v[i]][j]] == 1){flag = 1;break;}}}if(flag) cout << "No" <<endl;else cout << "Yes" <<endl;}return 0;
}

转载于:https://www.cnblogs.com/wanghao-boke/p/10458780.html

1149 Dangerous Goods Packaging (25 分)相关推荐

  1. 【PAT (Advanced Level) Practice】1149 Dangerous Goods Packaging (25 分)

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

  2. PAT甲级1149 Dangerous Goods Packaging :[C++题解]哈希表、逆向思维

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析: 本题要反着想:先把所有询问存起来,每个询问存在一个hash表中.然后对于每对不相容的物品,查看是否同时在一个hash表中. ac代码 ...

  3. PAT A1149 Dangerous Goods Packaging ——闲云潭影日悠悠,物换星移几度秋

    PAT A1149 Dangerous Goods Packaging 和单身狗那道题类似,不同的是,这里的狗都可以脚踏N只船(我最开始都没注意到,,) 所以首先多对多关系存入二维数组,然后维护一个标 ...

  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. 12门课100分直博清华!这份成绩单冲上热搜,但学霸小伙也曾考过25分

    点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 金磊 明敏 发自 凹非寺 量子位 报道 | 公众号 QbitAI 一 ...

  6. PTA 7-3 旅游规划 (25分)(双权值Dijkstra最短路)

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

  7. PTA 03-树1 树的同构 (25分)

    题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/711 5-3 树的同构   (25分) 给定两棵树T1和T2.如果T1可以通过若干次左右 ...

  8. 【PAT (Advanced Level) Practice】1051 Pop Sequence (25 分)

    1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the order ...

  9. 【PAT (Advanced Level) Practice】1093 Count PAT‘s (25 分)

    1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...

最新文章

  1. Transform(CTM,Translate,Rotate,Scale)
  2. 41.虚拟存储器以及相关算法
  3. C#学习笔记(六):可空类型、匿名方法和迭代器
  4. GIT常用命令--拉取提交
  5. 用柠檬来发电真的可行吗?
  6. libvirt热迁移报Connection refused错误解决办法
  7. Jawin –Java/Win32互动项目 可调用DLL及COM的调用项目
  8. acm 3278(poj4001)
  9. python画三维图-Python使用matplotlib绘制三维图形示例
  10. 拼多多商家无货源,如何批量铺货?
  11. win10下装黑苹果双系统_Ubuntu 18.04.3+Windows10双系统安装全教程
  12. Form表单的重置按钮(type=“reset“)无法重置隐藏Input输入框的值
  13. UE高级性能剖析技术(三)-- Android内存分布和优化
  14. SEM竞价入门的4个基本常识|零基础必看
  15. linux宝塔重新安装,Linux服务器Windows系统 安装和卸载宝塔面板
  16. Linux C编程 itoa()函数 atoi()函数
  17. 职业规划系列:软件工程师的十大层次
  18. pta求一元二次方程的根
  19. 高质量APP广告变现,广告竞价优化策略不能少
  20. 客快物流大数据项目(九十二):ClickHouse的MergeTree系列引擎介绍和MergeTree深入了解

热门文章

  1. 【CV论文阅读】Rank Pooling for Action Recognition
  2. 网站上flv,MP4等格式的视频文件播放不出来的解决办法
  3. 创建存储过程时出现的This function has none of DETERMINISTIC, NO SQL解决办法
  4. arm-linux-gcc/ld/objcopy/objdump使用总结[zz]
  5. ASP.NET Web 服务、企业服务和 .NET Remoting 的性能
  6. 华为服务器系统蓝屏,服务器主机蓝屏
  7. 如何在redhat8里使用gcc命令_如何使用who命令检查用户登录信息
  8. oracle 日志切换太频繁,诊断一次Oracle日志切换频繁的问题
  9. java 线程强制停止线程_java多线程之停止线程
  10. Win32ASM学习[3]:局部变量