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 ...
随机推荐
- SpringCloud学习
1.SpringCloud的参考博客1 首先主要遇到的问题就是1.写好项目然后放到tomcat或者其他的容器中,然后稍微一点修改就要整个项目重新发布,非常麻烦,这就是微服务出现的契机了 基础知识 PS ...
- combineReducers 对数据进行拆分管以及使用immutable.js
1 使用combineReaducers 整合reducers import { combineReducers } from 'redux-immutable'; import { reducer ...
- Eclipse使用Maven时出现:Index downloads are disabled, search results may be incomplete.问题解决
https://www.cnblogs.com/EasonJim/p/6674099.html 1.全局设置 [Windows]->[Preferences]->[Maven]->勾 ...
- Centos7提示swap交换空间不足解决方法
一张图就能解决的问题,就不多bb了
- git配置config文件
1.Git有一个工具被称为git config,它允许你获取和设置变量:这些变量可以控制Git的外观和操作的各个方面.这些变量以等级的不同可以被存储在三个不同的位置: (1) /etc/gitconf ...
- lamp安装总结
1.安装准备 建一个目录用于存放各软件包的压缩文件, 如我把我的源码文件都放在了 /software目录下 切换到/software目录下,执行 wget http://dev.mysql.com ...
- ArrayList集合方法
- TypeScript 之 类型推导
https://m.runoob.com/manual/gitbook/TypeScript/_book/doc/handbook/Type%20Inference.html 类型推导:发生在初始化变 ...
- Scala实战
1. Eclipse中设置scala调试器 scala的调试器要选择Scala Application(new debuger)Launcher:开始选择图省事,选择了一个字母少的,亲切的Launch ...
- Java利用hanlp完成语句相似度分析的案例详解
分享一篇hanlp分词工具使用的小案例,即利用hanlp分词工具分析两个中文语句的相似度的案例.供大家一起学习参考! 在做考试系统需求时,后台题库系统提供录入题目的功能.在录入题目的时候,由于题目来源 ...