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 ...
随机推荐
- Sping--注解(一) 常用注解总结
Sping注解是很重要的一块.今天在这里对常用到的注解做个小结,会尽可能说得详细些. 推荐这个英文文档,官方文档当然是最好的.最近发现,学习东西,还是多看官方文档,最权威,最详细. https://d ...
- <--------------------------Java多态如何使用------------------------------>
11多态调用的三种格式 * A:多态的定义格式: * 就是父类的引用变量指向子类对象 父类类型 变量名 = new 子类类型(); 变量名.方法名(); * B: 普通类多态定义的格式 父类 变量名 ...
- MySQL Innodb Engine -- 文件格式(innodb_file_format)
======================================================== 在InnoDB 1.0.x版本之前,InnoDB 存储引擎提供了 Compact 和 ...
- 04C++const增强、枚举的增强
#include <iostream> int main(void) { //const定义常量--->const意味着只读 const int a; int const b; // ...
- ThinkPHP3.2 where方法的使用
where方法的用法是ThinkPHP查询语言的精髓,也是ThinkPHP ORM的重要组成部分和亮点所在,可以完成包括普通查询.表达式查询.快捷查询.区间查询.组合查询在内的查询操作.where方法 ...
- Revit 开发将自己的窗口设置为Revit窗口
在Revit开发中如果使用modeless的对话框,经常容易被Revit窗体覆盖,但是如果将窗体设为Topmost的话,当Revit失去焦点后,它又会遮住其他程序的界面,比如将Revit最小化后,To ...
- 装饰模式Decorator Pattern
1.主要优点 装饰模式的主要优点如下: (1) 对于扩展一个对象的功能,装饰模式比继承更加灵活性,不会导致类的个数急剧增加. (3) 可以对一个对象进行多次装饰,通过使用不同的具体装饰类以及这些装饰类 ...
- OpenGL纹理
如果不用头文件,把所有东西堆在同一个cpp文件中,会出现“超出GPU内存的错误!” 1 //我们自己的着色器类 #ifndef SHADER_H #define SHADER_H #include & ...
- Mongo导出mongoexport和导入mongoimport介绍
最近爬取mobike和ofo单车数据,需要存储在csv文件中,因为设计的程序没有写存储csv文件的方法,为了偷懒所以就继续存储到了MongoDB中.恰好MongoDB支持导出的数据可以是csv文件和j ...
- MatConvNet中关于vl_simplenn_display的一些分析
一.关于各层data size的分析 layer1: floor((224-7)/2)+1=109 这里7是filter大小,2是stride layer4: floor((109+0+1-3)/2 ...