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 (≤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 <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 分)的更多相关文章

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

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

  2. 1149 Dangerous Goods Packaging (25 分)

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

  3. 1149 Dangerous Goods Packaging

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

  4. PAT_A1149#Dangerous Goods Packaging

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

  5. 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 ...

  6. PAT A1122 Hamiltonian Cycle (25 分)——图遍历

    The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a gra ...

  7. PAT A1142 Maximal Clique (25 分)——图

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  8. [PAT] 1142 Maximal Clique(25 分)

    1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...

  9. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

随机推荐

  1. opencv::图像矩(Image Moments)

    矩的概念介绍 1.几何矩 2.中心距 3.中心归一化距 4.图像中心Center(x0, y0) 计算矩 moments( InputArray array, // 输入数据 bool binaryI ...

  2. std::tuple

    tuple,元组类型.头文件<tuple>,tuple是一个固定大小的不同类型(异质,heterogeneous)值的集合(这一点是tuple与其他常规STL容器的最大不同,即它可以同时存 ...

  3. Elastic Stack 简介

    一.ElasticSearch ElasticSearch 是一个基于 Apache Lucene 的开源搜索引擎.它通过RESTful API 来隐藏Lucene的复杂性,从而让全文搜索变得简单.不 ...

  4. Graylog源码分析

    上文主要介绍了Graylog的功能与架构,本篇我们来看看Graylog的源码 一. 项目启动(CmdLineTool) 启动基本做了这几件事:初始化logger,插件加载(这里用到了Java SPI机 ...

  5. winform事件

    C#winform最简单的方法就是拖控件,然后双击控件生成默认的事件.再此双击生成的只是事件的方法,事件的订阅在form.desigener.cs中,如 this.DBSelectBTN.Click ...

  6. 持久层框架JPA与Mybatis该如何选型

    一.现状描述 目前java 持久层ORM框架应用最广泛的就是JPA和Mybatis.JPA只是一个ORM框架的规范, 对该规范的实现比较完整就是Spring Data JPA(底层基于Hibernat ...

  7. 关于./xhost: unable to open display问题的解决

    看了很多大同小异的帖子,都没能解决这个问题,以下是我的实测经验,注意第三步,很关键. 注:以下操作在确保vncserver.xdpyinfo服务正常的情况下进行 第一步:root登录,启动vncser ...

  8. 第八篇 Flask中的蓝图

    随着业务代码的增加,将所有代码都放在单个程序文件中,是非常不合适的.这不仅会让代码阅读变得困难,而且会给后期维护带来麻烦.如下示例:我们在一个文件中写入多个路由,这会使代码维护变得困难. 如图所示,如 ...

  9. ArcGIS Engine空间分析之缓冲区分析的实现

    缓冲分析(BufferAnalysis)的结果是一个面状要素——即缓冲要素,点状要素.线状要素和面状要素,被缓冲分析功能处理过之后,它们的周围产生一个缓冲区域,该区域即新产生的面状要素. 在缓冲方向上 ...

  10. Splash的使用

    Splash Lua脚本http://localhost:8050 入口及返回值 function main(splash, args) splash:go("http://www.baid ...