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 Kwhich is the number of queries, followed by K lines of queries, each in the format:
n V1 V2 ... Vn
where n is the number of vertices in the list, and Vi'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:
6 10
6 2
3 4
1 5
2 5
3 1
4 1
1 6
6 3
1 2
4 5
6
7 5 1 4 3 6 2 5
6 5 1 4 3 6 2
9 6 2 1 6 3 4 5 2 6
4 1 2 5 1
7 6 1 3 4 5 2 6
7 6 1 2 5 4 3 1
Sample Output:
YES
NO
NO
NO
YES
NO
题意:判断是否为Hamiltonian Cycle:条件是简单回路(除最后一个结点以外只出现一次),并且相邻两点之间连通。
/** * Copyright(c) * All rights reserved. * Author : Mered1th * Date : 2019-02-28-00.13.48 * Description : A1122 */ #include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> #include<string> #include<unordered_set> #include<map> #include<vector> #include<set> using namespace std; ; ; int G[maxn][maxn]; int n,m,k; int main(){ #ifdef ONLINE_JUDGE #else freopen("1.txt", "r", stdin); #endif scanf("%d%d",&n,&m); fill(G[],G[]+maxn*maxn,INF); int u,v; ;i<m;i++){ scanf("%d%d",&u,&v); G[u][v]=G[v][u]=; } scanf("%d",&k); int t,a; ;i<k;i++){ scanf("%d",&t); vector<int> temp; bool vis[maxn]={false}; bool flag=true; ;j<t;j++){ scanf("%d",&a); temp.push_back(a); } ]!=temp[temp.size()-]){ printf("NO\n"); continue; } ;x<temp.size()-;x++){ ]]!= || vis[temp[x]]==true){ printf("NO\n"); flag=false; break; } else{ vis[temp[x]]=true; } } if(flag==false) continue; ;j<n;j++){ if(vis[j]==false){ printf("NO\n"); flag=false; break; } } if(flag) printf("YES\n"); } ; }
1122 Hamiltonian Cycle (25 分)的更多相关文章
- 1122 Hamiltonian Cycle (25 分)
1122 Hamiltonian Cycle (25 分) The "Hamilton cycle problem" is to find a simple cycle that ...
- 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特别不喜欢那些随便转载别人的原创文章又不给 ...
- 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 requests模块搭建http load压测环境
网上开源的压力测试工具超级的多,但是总有一些功能不是很符合自己预期的,于是自己动手搭建了一个简单的http load的压测环境 1.首先从最简单的http环境着手,当你在浏览器上输入了http://w ...
- JMeter 各组件介绍以及用法
录制脚本 常用组件 参数化 关联
- Spring 框架的历史
2002 年 10 月,Rod Johnson 撰写了一本名为 Expert One-on-One J2EE 设计和开发的书.本书由 Wrox出版,介绍了当时 Java 企业应用程序开发的情况,并指出 ...
- 99乘法表的正反写 (python的写法)
# 正写 j = 0 k = 0 while j < 10: j+=1 while k <10: k+=1 if j>k: k = 0 break else: print('{}*{ ...
- 短信验证登陆-中国网建提供的SMS短信平台
一.JAVA发送手机短信常见的有三种方式(如下所列): 使用webservice接口发送手机短信,这个可以使用sina提供的webservice进行发送,但是需要进行注册 使用短信mao的方式进行短信 ...
- 20165308 学习基础和C语言基础调查
学习基础和C语言基础调查 技能学习 我认为给学生具体的, 能实践的, 能马上看到因果关系的教材和练习, 是激发学生兴趣, 好奇心, 求知欲的好方法. -- 引用自<做中学> 老师博客中注重 ...
- Springboot技术点汇总
1. Springboot+MyBatis+druid 在启动类上面,添加注释@Configuration以及@ImportResource(location={"classpath:con ...
- cksum命令详解
Linux cksum命令 Linux cksum命令用于检查文件的CRC是否正确.确保文件从一个系统传输到另一个系统的过程中不被损坏. CRC是一种排错检查方式,该校验法的标准由CCITT所指定,至 ...
- 用PHP发送POST请求
/** * 发送post请求 * @param string $url 请求地址 * @param array $post_data post键值对数据 * @return string */ fun ...
- NutzWk 开发框架
官网: https://wizzer.cn/ 源码下载: https://github.com/wizzercn/NutzWk/ https://gitee.com/wizzer/NutzWk Int ...