-->
当前位置:首页 > 题库

PROGRAMMING:Judgment of Hamiltonian circuit

Luz5年前 (2021-05-10)题库486
Hamiltonian circuit is a concept of graph. If a sequence of vertices can contain all the vertices in a graph, adjacent vertices are connected by edges, and the first and last vertices of the sequence are the same, then it is called Hamiltonian circuit. I hope you can judge whether a given sequence is a Hamiltonian circuit.
###Input format:
In the first line, enter two integers n and M. n is the number of vertices (1 < n < 200) and M is the number of edges. In the next M line, the two vertex numbers of the edge in the undirected graph are given, starting from 1.
In the next line, enter an integer T, which is the number of sequences to be judged. In the next line T, the sequence to be judged is given. The format is as follows:
```
K V1 V2 …… VK
```
Where k is the length of the sequence and VI is the vertex number of the sequence.
###Output format:
For group t query, output judgment conclusion in one line. If it is a Hamiltonian circuit, output ` yes', otherwise output ` No``
###Input example:
Here is a set of inputs. For example:
```in
4 6
1 2
2 3
3 4
1 4
1 3
2 4
three
5 1 2 3 4 1
4 1 2 3 1
5 4 1 2 3 4
```
###Output example:
The corresponding output is given here. For example:
```out
YES
NO
YES
```







answer:If there is no answer, please comment