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 V​1​​ V​2​​ ... V​n​​

where n is the number of vertices in the list, and V​i​​'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 分)的更多相关文章

  1. 1122 Hamiltonian Cycle (25 分)

    1122 Hamiltonian Cycle (25 分) The "Hamilton cycle problem" is to find a simple cycle that ...

  2. PAT甲级 1122. Hamiltonian Cycle (25)

    1122. Hamiltonian Cycle (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...

  3. 1122. Hamiltonian Cycle (25)

    The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a gra ...

  4. PAT甲题题解-1122. Hamiltonian Cycle (25)-判断路径是否是哈密顿回路

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789799.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  5. PAT 1122 Hamiltonian Cycle[比较一般]

    1122 Hamiltonian Cycle (25 分) The "Hamilton cycle problem" is to find a simple cycle that ...

  6. PAT 1122 Hamiltonian Cycle

    The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a gra ...

  7. 1122 Hamiltonian Cycle

    题意:包含图中所有结点的简单环称为汉密尔顿环.给出无向图,然后给出k个查询,问每个查询是否是汉密尔顿环. 思路:根据题目可知,我们需要判断一下几个条件:(1).首先保证给定的环相邻两结点是连通的:(2 ...

  8. PAT1122: Hamiltonian Cycle

    1122. Hamiltonian Cycle (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...

  9. PAT_A1122#Hamiltonian Cycle

    Source: PAT A1122 Hamiltonian Cycle (25 分) Description: The "Hamilton cycle problem" is to ...

随机推荐

  1. 《DSP using MATLAB》Problem 6.13

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  2. Go Example--通道方向

    package main import "fmt" func main() { pings := make(chan string, 1) pongs := make(chan s ...

  3. shell-url-decode

    查询每个小时的clk ,然后获取对应的字段 #!/bin/bash urldecode(){ echo -e "$(sed 's/+/ /g;s/%\(..\)/\\x\1/g;')&quo ...

  4. debezium mongodb 集成测试

    debezium 是一个方便的cdc connector 可以帮助我们解决好多数据实时变更处理.数据分析.微服务的数据通信 从上次跑简单demo到现在,这个工具是有好多的变更,添加了好多方便的功能,支 ...

  5. 使用uflare/smtp2http 将smtp 转转化为http 请求

    uflare/smtp2http 是一个很不错的工具,我们使用这个工具,可以快速的将smtp 服务转换为http 服务 用途实际上挺多的 devops 系统 需要使用smtp的系统(测试) 基于smt ...

  6. 计算元素个数(count和count_if)

    count 计算first和last之间与value相等于元素个数 template <class InputIterator,class EqualityComparable> type ...

  7. MySQL创建计算字段

    数据库中数据表的格式一般不是应用程序所需要的格式,如: 在一个字段中既显示公司名有显示公司地址,但这两个数据一般不在一张表中 城市,州和邮政编码在不同的列中,但邮件标签打印程序需要把他们作为一个恰当的 ...

  8. Day 01 计算机组成和操作系统

    一.编程与编程语言 1.什么是语言?什么是编程语言? 答:语言是一种事物与另一种事物沟通的介质. 编程语言是程序员与计算机沟通的介质. 2.什么是编程? 答:程序员把自己想要让计算机做的事用编程语言表 ...

  9. java-保留x个小数位

    public BigDecimal setScale(int newScale,RoundingMode roundingMode)返回 BigDecimal,其标度为指定值,其非标度值通过此 Big ...

  10. 网易云课堂js学习笔记

    javascript:用来在页面中编写特效的,和html/css一样都是由浏览器解析的 javascript语言: 一.js如何运行的(javaScript,jscript,vbscript,appl ...