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 ...
随机推荐
- oracle初级系列教程
https://www.cnblogs.com/linjiqin/category/349944.html
- i春秋DMZ大型靶场实验(三)内网转发DMZ2
更具实验文件知道存在源码泄露 下载源码进行源码审计 发现admin账号 查看user.php 发现mysql 账号 端口 对登录后源码进行审计 发现上传文件的两处漏洞 对 fiel name 可以 ...
- HTML5+WebGL 的加油站 3D 可视化监控
前言 随着数字化,工业互联网,物联网的发展,我国加油站正向有人值守,无人操作,远程控制的方向发展,传统的人工巡查方式逐渐转变为以自动化控制为主的在线监控方式,即采用数据采集与监控系统 SCADA.SC ...
- Arduino学习笔记③ 经典LED
1.前言 今天我们开始同时讲解理论以及实践.对于绝大部分有过单片机编程经历的人来说,第一个接触的大多数就是LED灯(忽然想起博主大一那个懵懂的时代,当时大三的师兄给我们展现了一把流水灯功力,当 ...
- Vultr新用户充值送50刀
充值送50刀 活动还是可以的,充个10刀,适合用来当测试服,按时间计费
- JVM - 复习
内存模型图 程序计数器(PC) 程序计数器的特点 PC是一小块内存空间,用于记录当前线程执行的字节码指令的地址.如果执行的是本地方法(native),PC里此时显示Undefined 优点: 控制程序 ...
- Java线程切换(一)
(本文由言念小文原创,转载请注明出处) 一 前言有Android开发经验的同学都清楚,UI的更新必须在主线程中进行,且主线程不能被阻塞,否则系统ANR异常.我们往往做一些数据处理是耗时操作,必须要在 ...
- LeetCode刷题笔记(6)按照索引计算int[] 数组中的和([Time Limit Exceeded]问题)
Easy303 Easy633 package easy; public class e303 { private int[] sums; public e303(int[] nums) { sums ...
- day2------运算符和编码
运算符和编码 一. 格式化输出 现在有以下需求,让用户输入name, age, job,Gender 然后输出如下所示: ------------ info of Yong Jie --------- ...
- Java 发展历程
JDK 1.0 1991年4月,由 James Gosling 博士领导的绿色计划(Green Project)开始启动,此计划的目的是开发一种能够在各种消费性电子产品(如机顶盒.冰箱.收音机等)上运 ...