pat 1149 Dangerous Goods Packaging(25 分)
1149 Dangerous Goods Packaging(25 分)
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 (≤104), 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 <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define wzf ((1 + sqrt(5.0)) / 2.0)
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int MAX = 1e6 + ; vector <int> ve[MAX];
int book[MAX]; int main()
{
freopen("Date.txt", "r", stdin);
int n, m, a, b, k;
scanf("%d%d", &n, &m);
while (n --)
{
scanf("%d%d", &a, &b);
ve[a].push_back(b);
ve[b].push_back(a);
}
while (m --)
{
scanf("%d", &k);
bool flag = false;
memset(book, , sizeof(book));
while (k --)
{
scanf("%d", &a);
if (flag) continue;
if (book[a])
{
flag = true;
printf("No\n");
continue;
}
for (int i = ; i < ve[a].size(); ++ i)
book[ve[a][i]] = ;
}
if (!flag) printf("Yes\n");
}
return ;
}
pat 1149 Dangerous Goods Packaging(25 分)的更多相关文章
- PAT A1149 Dangerous Goods Packaging (25 分)——set查找
When shipping goods with containers, we have to be careful not to pack some incompatible goods into ...
- 1149 Dangerous Goods Packaging (25 分)
When shipping goods with containers, we have to be careful not to pack some incompatible goods into ...
- 1149 Dangerous Goods Packaging
When shipping goods with containers, we have to be careful not to pack some incompatible goods into ...
- PAT_A1149#Dangerous Goods Packaging
Source: PAT A1149 Dangerous Goods Packaging (25 分) Description: When shipping goods with containers, ...
- PAT 1009 Product of Polynomials (25分) 指数做数组下标,系数做值
题目 This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: E ...
- PAT A1122 Hamiltonian Cycle (25 分)——图遍历
The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a gra ...
- PAT A1142 Maximal Clique (25 分)——图
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- [PAT] 1142 Maximal Clique(25 分)
1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
随机推荐
- 【Spring Cloud】实战项目搭建
0.项目搭建 创建maven项目,删除其中的src目录,作为整体父项目,在其中添加module实现各个组件. 1.Eureka Server的实现 添加module,创建Spring Boot项目,添 ...
- C#类,对象,类成员简介
本节内容 1.类(class)是现实世界事物的模型 2.类与对象的关系,什么时候叫“对象”什么时候叫“实例” 3.引用变量与实例的关系 4.类的三大成员: ①属性(Property): ②方法(Met ...
- Spring Boot项目中使用Mockito
本文首发于个人网站:Spring Boot项目中使用Mockito Spring Boot可以和大部分流行的测试框架协同工作:通过Spring JUnit创建单元测试:生成测试数据初始化数据库用于测试 ...
- 《HTML5+CSS3+JavaScript 从入门到精通(标准版)》学习笔记(二)
这是一个应用的例子,学以致用嘛 <!--这些代码我就直接放在了博客园的"页首Html代码"中,用于自定义博客,效果就是页面左上角的白色文字--> <p> & ...
- git 的一些指令
作为一个前端,git的各种指令应该是需要掌握的,因为前一段时间遇到了一些问题,总觉得每次遇到点问题都去百度这样总归不大好,还是记录一下比较常见的一些指令吧.以后遇到新的再继续添加. 1. 新建本地分支 ...
- django-常见问题勘误
1.NoReverseMatch at / Reverse for 'about' not found. 'about' is not a valid view function or pattern ...
- SpringBoot整合Logback
本文主要讲与Boot整合,后面会详细讲解Logback 官方文档 ConsoleAppender 如 name 所示,附加在 console 上,或者更准确地说是 System.out 或 Syste ...
- 设计模式C++描述----10.装饰(Decorator)模式
一. 举例 我之前做过一个文件系统就叫 MyFileSys 吧,后来的话,客户想加入一些附加功能,比如压缩.加密.杀毒之类的操作,这些附加操作没有先后顺序,比如你可以先压缩再加密,也可以先杀毒再压缩, ...
- 第九篇 Flask的before_request和after_request
Flask我们已经学习很多基础知识了,现在有一个问题 我们现在有一个 Flask 程序其中有3个路由和视图函数,如下: from flask import Flask app = Flask(__na ...
- postman的监控接口响应时间monitor
Monitor简介1.是基于Postman集合API的灵活监控 2.监控API的正常运行时间.响应能力和正确性 3.提供监测结果的详细报告 4.对所有Postman用户每月提供1000个免费的监控请求 ...