This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 1e3+5;
vector<int> g[N], b;
void dfs(int s, int e = -1) {
bool t = 0;
b.pb(s);
for (auto u : g[s]) {
if (u == e) continue;
if (t && g[u].size() > 1) {
cout << "NO\n";
exit(0);
}
if (g[u].size() > 1) {
dfs(u, s);
t = 1;
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
if (n == 1) {
cout << "YES\n1\n1\n";
return 0;
}
if (n == 2) {
cout << "YES\n2\n1 1\n";
return 0;
}
if (m >= n) {
cout << "NO\n";
exit(0);
}
for (int i = 1; i <= n; ++i) {
if (g[i].size() > 1) {
int t = 1;
for (auto u : g[i]) {
if (g[u].size() > 1) t--;
}
if (t >= 0) {
dfs(i);
cout << "YES" << '\n';
cout << 2*b.size() << '\n';
for (auto x : b) cout << x << ' ';
if (b.size() % 2 == 0) reverse(b.begin(), b.end());
for (auto x : b) cout << x << ' ';
cout << '\n';
return 0;
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |