#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;
struct DSU{
int n;
vi p;
vi sz;
DSU(int _n){
n=_n;
p.resize(n);
iota(all(p),0);
sz.resize(n);
fill(all(sz),1);
}
int find(int a){
return p[a]==a?a:p[a]=find(p[a]);
}
bool merge(int a, int b){
if(find(a)==find(b))return false;
int pa=find(a);
int pb=find(b);
if(sz[pa]<sz[pb])swap(pa,pb);
sz[pa]+=sz[pb];
p[pb]=pa;
return true;
}
};
bool ans=true;
vi c;
vector<vi> adj;
void dfs(int v, int p,int _c){
if(~c[v]){
if(c[v]!=_c)
ans=false;
return;
}
c[v]=_c;
trav(u,adj[v]){
if(u==p)continue;
dfs(u,v,_c^1);
}
}
void solve(){
int n,m;
cin>>n>>m;
adj.resize(n);
c.resize(n,-1);
DSU dsu(n);
F0R(i,m){
int a,b;
cin>>a>>b;
--a,--b;
adj[a].pb(b);
adj[b].pb(a);
// if(!dsu.merge(a,b)){
// ans=false;
// }
}
dfs(0,-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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |