1122 Hamiltonian Cycle (25 分)
1122 Hamiltonian Cycle (25 分)
The “Hamilton cycle problem” is to find a simple cycle that contains every vertex in a graph. Such a cycle is called a “Hamiltonian cycle”.
In this problem, you are supposed to tell if a given cycle is a Hamiltonian cycle.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 positive integers N (2<N≤200), the number of vertices, and M, the number of edges in an undirected graph. Then M lines follow, each describes an edge in the format Vertex1 Vertex2, where the vertices are numbered from 1 to N. The next line gives a positive integer K which is the number of queries, followed by K lines of queries, each in the format:
n V1 V2 … V**n
where n is the number of vertices in the list, and V**i‘s are the vertices on a path.
Output Specification:
For each query, print in a line YES if the path does form a Hamiltonian cycle, or NO if not.
Sample Input:
1 |
6 10 |
Sample Output:
1 |
YES |
作者: CHEN, Yue
单位: 浙江大学
时间限制: 300 ms
内存限制: 64 MB
代码长度限制: 16 KB
题目大意
给出一个图,要求判断一个环是否是Hamiltonian cycle。题目对这个定义说得挺不清楚的。其实就是必须是简单环(除起点终点不能重复)而且图中所有点都要访问一次。
代码
1 |
#include <vector> |
1122 Hamiltonian Cycle (25 分)的更多相关文章
- PAT甲级 1122. Hamiltonian Cycle (25)
1122. Hamiltonian Cycle (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
- 1122. Hamiltonian Cycle (25)
The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a gra ...
- PAT甲题题解-1122. Hamiltonian Cycle (25)-判断路径是否是哈密顿回路
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789799.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 1122 Hamiltonian Cycle (25 分)
1122 Hamiltonian Cycle (25 分) The "Hamilton cycle problem" is to find a simple cycle that ...
- PAT 1122 Hamiltonian Cycle[比较一般]
1122 Hamiltonian Cycle (25 分) The "Hamilton cycle problem" is to find a simple cycle that ...
- PAT 1122 Hamiltonian Cycle
The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a gra ...
- 1122 Hamiltonian Cycle
题意:包含图中所有结点的简单环称为汉密尔顿环.给出无向图,然后给出k个查询,问每个查询是否是汉密尔顿环. 思路:根据题目可知,我们需要判断一下几个条件:(1).首先保证给定的环相邻两结点是连通的:(2 ...
- PAT1122: Hamiltonian Cycle
1122. Hamiltonian Cycle (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
- PAT_A1122#Hamiltonian Cycle
Source: PAT A1122 Hamiltonian Cycle (25 分) Description: The "Hamilton cycle problem" is to ...
随机推荐
- Python笔记_第二篇_面向过程_第二部分_6.包
1. 包: 思考:如果不同人的编写模块同名了怎么办? 解决:为了解决模块命名的冲突,引入了按目录来组织模块的方法,这个目录成为“包” 特点:引入了包以后,只要丁顶层的包,不与其他人发生冲突,那么模块都 ...
- [前端] VUE基础 (5) (过滤器、生命周期、钩子函数)
一.过滤器 过滤器分为局部过滤器和全局过滤器. 1.局部过滤器 <body> <div id="app"> </div> <script ...
- 线段树、最短路径、最小生成树、并查集、二分图匹配、最近公共祖先--C++模板
线段树(区间修改,区间和): #include <cstdio> #include <iostream> #include <cstring> using name ...
- 17.3.16---python内建函数
内置函数,无需import,任何时候都可以直接被使用 1------ Python针对众多的类型,提供了众多的内建函数来处理(内建是相对于导入import来说的,后面学习到包package时,将会介绍 ...
- yuyuecms 1.2文件删除漏洞
www.yuyue-cms.com yuyuecms版本1.2 管理员/索引控制器删除方法中的漏洞 请参阅catfishcmsCatfish isPost静态方法 如果调用后验证静态方法 如果为tru ...
- Python图形验证码识别
一,OCR OCR,即Optical Character Recognition,光学字符识别,通过扫描字符,分析形状,然后将其翻译成电子文本的过程.tesserocr是Python的一个OCR识别库 ...
- 与http协作的web服务器
1.虚拟主机 一台web服务器可以搭建多个独立域名的web网站,也可以作为通信线路上的中转服务器提升传输效率.比如web托管服务供应商可以用一台服务器为多个不同域名的客户提供服务,这是利用了虚拟主机( ...
- Opencv笔记(六)——把滑动条当调色板
学习目标: 学会把滑动条绑定到 OpenCV 的窗口. 学习函数:cv2.getTrackbarPos(), cv2.creatTrackbar()等. 简单演示: 通过调节滑动条来设定画板颜色.我们 ...
- 【网络流】One-Way Roads
[网络流]One-Way Roads 题目描述 In the country of Via, the cities are connected by roads that can be used in ...
- CSS样式表---------第三章:样式属性
三.样式属性 1.背景与前景 background-color:#90; ------------背景色,样式表优先级高. background-image:url(路径)-------------- ...