Submission #1183476

#TimeUsernameProblemLanguageResultExecution timeMemory
1183476MighilonNewspapers (CEOI21_newspapers)C++20
4 / 100
0 ms328 KiB
#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;
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){
    if(_d>=2){
        ans=false;
    }
    trav(u,adj[v]){
        if(u==p)continue;
        if(!c[u]) dfs2(u,v,_d+1);
        else dfs2(u,v,0);
    }
}

void solve(){
    int n,m;
    cin>>n>>m;
    adj.resize(n);
    d.resize(n,0);
    p.resize(n,-1);
    c.resize(n,0);
    F0R(i,m){
        int a,b;
        cin>>a>>b;
        --a,--b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(0,-1,0);
    if(!ans){
        cout<<"NO"<<nl;
        return;
    }
    int si=max_element(all(d))-d.begin();
    fill(all(d),0);
    dfs(si,-1,0);
    int sj=max_element(all(d))-d.begin();
    vi line;
    int tmp=sj;
    while(tmp!=-1){
        line.pb(tmp);
        tmp=p[tmp];
    }
    trav(i,line){
        c[i]=1;
    }
    dfs2(sj,-1,0);
    if(ans){
        cout<<"YES \n2\n1 1"<<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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...