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 ...
随机推荐
- IDEA查看接口的所有实现类
查看实现类 接口下右键Diagrams->Show Diagram,选中接口右键Show Implementations 或接口下按Ctrl+H: 或接口类名左边按钮:
- npm安装依赖报 npm ERR! code Z_BUF_ERROR npm ERR! errno -5 npm ERR! zlib: unexpected end of file 这个错误解决方案
今天碰到了一个比较奇怪的问题,下载依赖有问题报错 npm ERR! code Z_BUF_ERROR npm ERR! errno -5 npm ERR! zlib: unexpected end o ...
- 计量经济与时间序列_ACF自相关与PACF偏自相关算法解析(Python,TB(交易开拓者))
1 在时间序列中ACF图和PACF图是非常重要的两个概念,如果运用时间序列做建模.交易或者预测的话.这两个概念是必须的. 2 ACF和PACF分别为:自相关函数(系数)和偏自相关函数(系数). ...
- 学习数论 HDU 4709
经过杭师大校赛的打击,明白了数学知识的重要性 开始学习数论,开始找题练手 Herding HDU - 4709 Little John is herding his father's cattles. ...
- iOS 添加view的分类(更加方便的设置view的位置)
点击创建UIView的分类category,这里命名为 PLExtension(为了和下面对应) view分类.h文件 #import <UIKit/UIKit.h> @interface ...
- 微信小程序裁剪图片后上传
上传图片的时候调起裁剪页面,裁剪后再回调完成上传; 图片裁剪直接用we-cropper https://github.com/we-plugin/we-cropper we-cropper使用详细 ...
- Win10用Windows照片查看程序(照片查看器)打开图片
以上方法只能一个个添加,也有人说不好使,这里给出一个我写的批处理程序,反正我一直用着很好. ::复制以下内容到记事本: @echo off&cd\&color 0a&cls ...
- 上传excel文件,读取内容,增加事务写入数据库
package com.inspur.icpmg.itss.asset.dao.impl; import com.inspur.icpmg.util.DBHelper; import org.apac ...
- 记录ionic 最小化应用时所遇的问题
ionic3与ionic4最小化插件安装不一样: ionic3安装方法: $ ionic cordova plugin add cordova-plugin-appminimize $ npm ins ...
- jenkins-定时跑代码
build periodically和poll scm都可以定时运行