Submission #779354

#TimeUsernameProblemLanguageResultExecution timeMemory
779354FEDIKUSNewspapers (CEOI21_newspapers)C++17
50 / 100
155 ms8236 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...