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;
const int maxn=1010;
bool moze=true;
vector<int> g[maxn];
int dfs(int node,int parent=-1){
int ret=0;
int klk=0;
for(int i:g[node]){
if(i==parent) continue;
auto temp=dfs(i,node);
ret=max(ret,temp);
if(temp>2) klk++;
}
if(klk>2) moze=false;
ret++;
return ret;
}
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
if(m!=n-1){
cout<<"NO\n";
return 0;
}
for(int i=1;i<=n;i++) dfs(i);
if(moze) cout<<"YES\n1\n1";
else cout<<"NO\n";
return 0;
}
/*
7 6
1 2
1 3
1 4
1 5
1 6
1 7
6 6
1 2
2 3
3 1
1 4
2 5
3 6
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |