博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1122 Hamiltonian Cycle (25 分)
阅读量:5144 次
发布时间:2019-06-13

本文共 1911 字,大约阅读时间需要 6 分钟。

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<N200), 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:

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 106 23 41 52 53 14 11 66 31 24 567 5 1 4 3 6 2 56 5 1 4 3 6 29 6 2 1 6 3 4 5 2 64 1 2 5 17 6 1 3 4 5 2 67 6 1 2 5 4 3 1

Sample Output:

YESNONONOYESNO 题意:判断是否为Hamiltonian Cycle:条件是简单回路(除最后一个结点以外只出现一次),并且相邻两点之间连通。
1 /** 2 * Copyright(c) 3 * All rights reserved. 4 * Author : Mered1th 5 * Date : 2019-02-28-00.13.48 6 * Description : A1122 7 */ 8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 using namespace std;19 const int maxn=210;20 const int INF=1000000000;21 int G[maxn][maxn];22 int n,m,k;23 int main(){24 #ifdef ONLINE_JUDGE25 #else26 freopen("1.txt", "r", stdin);27 #endif28 scanf("%d%d",&n,&m);29 fill(G[0],G[0]+maxn*maxn,INF);30 int u,v;31 for(int i=0;i
temp;40 bool vis[maxn]={ false};41 bool flag=true;42 for(int j=0;j

 

 

转载于:https://www.cnblogs.com/Mered1th/p/10449687.html

你可能感兴趣的文章
Linux环境下Redis安装和常见问题的解决
查看>>
HashPump用法
查看>>
cuda基础
查看>>
Vue安装准备工作
查看>>
oracle 创建暂时表
查看>>
201421410014蒋佳奇
查看>>
Xcode5和ObjC新特性
查看>>
LibSVM for Python 使用
查看>>
Centos 7.0 安装Mono 3.4 和 Jexus 5.6
查看>>
CSS属性值currentColor
查看>>
java可重入锁reentrantlock
查看>>
浅谈卷积神经网络及matlab实现
查看>>
解决ajax请求cors跨域问题
查看>>
《收获,不止Oracle》pdf
查看>>
LinkedList<E>源码分析
查看>>
Real-Time Rendering 笔记
查看>>
如何理解HTML结构的语义化
查看>>
Activity之间的跳转:
查看>>
实验四2
查看>>
Android现学现用第十一天
查看>>