1122. Hamiltonian Cycle (25) 图论 23'
程序员文章站
2022-03-08 16:17:58
...
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
bool e[201][201];
int main(){
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
e[a][b] = e[b][a] = 1;
}
int k;
cin >> k;
for (int i = 0; i < k; i++) {
int c, flag = 1;
cin >> c;
vector<int> temp(c), visited(c, 0);
for (int j = 0; j < c; j++) cin >> temp[j];
if(c != n + 1 || temp[0] != temp[c-1]) flag = 0;
if (flag) {
for (int i = 0; i < c - 1; i++) {
visited[temp[i]]++;
}
for (int i = 1; i < c; i++) {
if(visited[i] != 1) {flag = 0; break;}
}
}
if(flag) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
推荐阅读
-
PAT 甲级 1122. Hamiltonian Cycle (25)
-
【PAT】1122. Hamiltonian Cycle (25)
-
PAT甲1122 Hamiltonian Cycle(25 分)
-
[Python](PAT)1122 Hamiltonian Cycle(25 分)
-
A1122 Hamiltonian Cycle (25 分| 图论,附详细注释,逻辑分析)
-
PAT (Advanced Level) Practice - 1122 Hamiltonian Cycle(25 分)
-
PAT甲级 1122. Hamiltonian Cycle (25)
-
1122 Hamiltonian Cycle (25 分)
-
1122 Hamiltonian Cycle (25 分)
-
1122 Hamiltonian Cycle(25 分)