#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define MAX 1000
lli a,b,m,n;
vector<lli> hijos[MAX+2];
vector<lli> res;
lli tam[MAX+2];
void pre_dfs(lli pos, lli padre) {
tam[pos] = 1;
for(auto h : hijos[pos]) {
if (h == padre) continue;
pre_dfs(h,pos);
tam[pos] += tam[h];
}
}
bool checa(lli pos, lli padre) {
lli sig,may = 0;
res.push_back(pos);
for(auto h : hijos[pos]) {
if(h == padre) continue;
if (tam[h] > 1) {
may++;
sig = h;
}
}
if (may > 1) return false;
if (may == 0) return true;
return checa(sig,pos);
}
bool sepuede(lli raiz) {
res.clear();
pre_dfs(raiz,0);
return checa(raiz,0);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
rep(i,1,m) {
cin >> a >> b;
hijos[a].push_back(b);
hijos[b].push_back(a);
}
if (m >= n) {
cout << "NO";
return 0;
}
rep(i,1,n) {
if (hijos[i].size() == 1 && sepuede(i)) {
cout << "YES\n";
cout << (res.size()*2-2) << "\n";
for(auto r : res) if (r != i) cout << r << ' ';
reverse(res.begin(), res.end());
for(auto r : res) if (r != i) cout << r << ' ';
return 0;
}
}
cout << "NO";
return 0;
}
Compilation message
newspapers.cpp: In function 'bool checa(long long int, long long int)':
newspapers.cpp:42:17: warning: 'sig' may be used uninitialized in this function [-Wmaybe-uninitialized]
42 | return checa(sig,pos);
| ~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |