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 ...
随机推荐
- 如何新建oracle数据库,图文流程。
系统环境:Windows server 2008 R2 企业版 SP1 软件版本:oracle 11g win64位 默认oracle 11g 安装配置完成,我们该如何创建数据库? 我们就介绍最基本 ...
- 《DSP using MATLAB》Problem 5.24-5.25-5.26
代码: function y = circonvt(x1,x2,N) %% N-point Circular convolution between x1 and x2: (time domain) ...
- MySQL Network--Localhost与127.0.0.1的差异
localhost为本地服务器,而127.0.01为本机地址.在使用localhost时不经过网卡传输,不受网络防火墙和网卡相关的限制,访问localhost不会被解析成ip地址,不会占用网卡和网络资 ...
- MySQL--查看内存信息
常见查看内存信息命令 ## 使用free -m命令查看 free -m ## 使用cat /proc/meminfo 查看 cat /proc/meminfo ## 使用dmidecode命令查看 d ...
- C# Monitor的Wait和Pulse方法使用详解
[转载]http://blog.csdn.net/qqsttt/article/details/24777553 Monitor的Wait和Pulse方法在线程的同步锁使用中是比较复杂的,理解稍微困难 ...
- 记录:.user.ini 使用
记录:.user.ini 使用 可以用于防跨站配置. .user.ini 注意安全问题 动态加载,默认 5 分钟自动刷新. php 5.3 以后的版本支持. 修改完成后再将文件锁定. 相关链接: 神秘 ...
- 不用修改 hosts 本地开发(续篇)
上一篇说过不修改 hosts 在 Chrome 中可以使用 *.localhost 进行绑定域名开发. 但只能用于 Chrome 中,今天找了一个还有一些好心人提供了域名指向 127.0.0.1 . ...
- 我发起了一个 用 C 语言 作为 中间语言 的 编译器 项目 VMBC
大家好 , 我发起了一个 用 C 语言 作为 中间语言 的 编译器 项目 VMBC . VMBC , 全称是 Virtual Machine Base on C . 有一种说法 , C 语言是 ...
- 上外网tunnel手段
需要的软件 1, httptunnel软件,包括服务端和客户端,家里开启服务端,公司开启客户端 2,(可选)proxifier PE,用来在公司check 代理工作是否正常 3,动态域名服务,在家里用 ...
- mysql主从复制--重置操作reset master, reset slave
本文介绍reset master, reset slave的作用. reset master 在master上执行 mysql > RESET MASTER 作用包括: 删除binlog索引文件 ...