#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "../Library/debug.h"
#else
#define dbg(x...)
#endif
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i)
#define trav(a, x) for (auto& a : x)
#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
const char nl = '\n';
const int INF = 1e9;
const ll MOD = 998244353;
const int mxN = 3e5+5;
bool ans=true;
vi d,p,c,co;
vector<vi> adj;
void dfs(int v, int _p,int _d){
if(d[v]){
ans=false;
return;
}
p[v]=_p;
d[v]=_d;
trav(u,adj[v]){
if(u==_p)continue;
dfs(u,v,_d+1);
}
}
void dfs2(int v,int p,int _d,int _c){
if(_d>=3){
ans=false;
}
d[v]=_d;
co[v]=_c;
trav(u,adj[v]){
if(u==p)continue;
if(!c[u]) dfs2(u,v,_d+1,_c^1);
else dfs2(u,v,0,_c^1);
if(!c[v]){
d[v]=d[u];
}
}
}
vi vans;
// void dfs3(int v, int p,int _c){
// if(sz(vans)%2==0)
// }
void solve(){
int n,m;
cin>>n>>m;
adj.resize(n);
d.resize(n,0);
p.resize(n,-1);
c.resize(n,0);
co.resize(n,-1);
F0R(i,m){
int a,b;
cin>>a>>b;
--a,--b;
adj[a].pb(b);
adj[b].pb(a);
}
dfs(0,-1,0);
int si=max_element(all(d))-d.begin();
fill(all(d),0);
dfs(si,-1,0);
int sj=max_element(all(d))-d.begin();
fill(all(d),0);
vi line;
int tmp=sj;
while(tmp!=-1){
line.pb(tmp);
tmp=p[tmp];
}
dbg(line)
trav(i,line){
c[i]=1;
}
dfs2(sj,-1,0,0);
if(!ans){
cout<<"NO"<<nl;
return;
}
int _c=co[sj];
F0R(i,sz(line)){
int v=line[i];
vans.pb(v);
trav(u,adj[v]){
if(c[u]==1||d[u]==1)continue;
assert(d[u]==2);
vans.pb(u);
vans.pb(v);
}
}
// if(sz(vans)%2==0)
// vans.pb(0);
// int _sz=sz(vans);
// F0R(i,_sz-1)
// vans.pb(vans[i]);
dbg(d)
dbg(co)
dbg(vans)
if(ans){
cout<<"YES"<<nl;
cout<<sz(vans)<<nl;
trav(i,vans)cout<<i+1<<" ";
cout<<nl;
}
else{
cout<<"NO"<<nl;
}
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int TC = 1;
// cin >> TC;
while(TC--){
solve();
}
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... |