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 ...
随机推荐
- JavaScript-改变this指向
一.this指向的详解 概括:this的指向到底是指向哪里?通常来说,只有当函数执行的时候才可以确定this指向的到底是谁,简单的也可以这么说:this最终指向的是那个调用它的对象. 常见的一般有以下 ...
- 网页背景H5视频自动播放---PC端、移动端兼容问题完美解决方案(IOS、安卓、微信端)
最近公司官网需要使用视频当做banner背景且自动播放,并且因为是官网需要做到PC端和移动端都可以适配兼容,这些问题很是头疼: 兵来将挡,水来土掩,进过查阅相关技术资料,现已完美兼容PC端和移动端.下 ...
- CentOS7使用‘中科大源’
中科大的源质量速度都不错,推荐使用. 这里列出CentOS 7的Base和epel的源. 进入/etc/yum.repos.d/中,将原本的几个repo文件备份,之后新建三个repo文件 内容如下: ...
- cxf 调用 .net webservice
1. 问题背景 现在我们两套语言并行,其中必然会涉及到不同系统的相互访问. .net 的会员信息是用 webservice 提供服务的.那如何对现有 .net webservi ...
- Java基础(二十六)Java IO(3)字节流(Byte Stream)
字节流是以字节为单位来处理数据的,由于字节流不会对数据进行任何转换,因此用来处理二进制的数据. 一.InputStream类与OutputStream类 1.InputStream类是所有字节输入流的 ...
- 接口 IEnumerable
C#提供了可供类继承的接口,在此解释一下经常遇到的IEnumerable,在此首相解释一下接口,如下例所示: /// <summary> /// 简述Interface的用法 /// &l ...
- mysql中if函数的正确使用姿势
--为了今天要写的内容,运行了将近7个小时的程序,在数据库中存储了1千万条数据.-- 今天要说的是mysql数据库的IF()函数的一个实例. 具体场景如下, 先看看表结构: CREATE TABLE ...
- jupyter notebook启动需要输入密码的问题
问题描述: 安装完jupyter notebook之后,启动时需要输入密码,如下图所示: 解决方法: 1.启动jupyter notebook 2.在另一个的终端中输入 jupyter noteboo ...
- 第九篇 Flask的before_request和after_request
Flask我们已经学习很多基础知识了,现在有一个问题 我们现在有一个 Flask 程序其中有3个路由和视图函数,如下: from flask import Flask app = Flask(__na ...
- Mycat分布式数据库架构解决方案--Mycat实现读写分离
echo编辑整理,欢迎转载,转载请声明文章来源.欢迎添加echo微信(微信号:t2421499075)交流学习. 百战不败,依不自称常胜,百败不颓,依能奋力前行.--这才是真正的堪称强大!!! 安装完 ...