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. 【JVM】java对象

    一.对象内存布局 对象在内存中存储可分为3块区域:对象头,实例数据,对齐填充 1.对象头 对象头包含两部分内容. 第一部分:存储对象自身的运行时数据,哈希吗(hashCode),GC分代年龄,锁状态标 ...

  2. 使用mongoose连接mongodb(转载文章)

    mongodb数据库 MongoDB是一个高效的基于分布式文件存储的数据库,将数据存储为一个文档,数据结构由键值(key=>value)对组成.MongoDB 文档类似于 JSON 对象.字段值 ...

  3. java的数组和arraylist

    1.数组 1.0   一开始就错了 int a[8];   //没有像C在内存中开辟了8个区域 改: int a[] = {1,2,3} ; System.out.println(a.length); ...

  4. linux 控制结构

    一.if 注: 格式1.格式2:一个条件一个命令: 格式3:一个条件两个命令: 格式4:两个条件三个命令,注意条件的写法. 例1: #!/bin/sh#ifTest#to show the metho ...

  5. wpf学习

    http://www.jikexueyuan.com/course/1231_3.html?ss=1 WPF入门教程系列二——Application介绍 http://www.cnblogs.com/ ...

  6. TP5 中引入第三方类库

    通过了解tp5的目录结构,我们知道其中有两个目录是纺织扩展类库文件的. extend是放置自定义或者其他类文件的. vendor目录是放置composer类库文件的. 当我们的第三方类库文件是下载的, ...

  7. php+js实现重定向跳转并post传参

    页面重定向跳转并post传参 $mdata=json_encode($mdata);//如果是字符串无需使用json echo " <form style='display:none; ...

  8. workerman的使用实践--并与solaris通信

    Workerman与solarisTCP通信测试 1.  笔记本win7,tcp_test.php 2.  solaris,test.c 编译命令: gcc test.c –o  test –lsoc ...

  9. 安装plsql developer

    需求:要连接oracle数据库,不想在本地安装oracle,太大,又占内存,所以用plsql developer.. 在网上看了很多博客,妈呀,被毒的不清,一直提示初始化失败,就是那个oci,dll ...

  10. 报错: unable to register MBean

    解决方法: 在SpringBoot项目中配置文件加上 spring.jmx.enabled=false https://stackoverflow.com/questions/27440985/una ...