Submission #589312

#TimeUsernameProblemLanguageResultExecution timeMemory
589312jasminWells (CEOI21_wells)C++17
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> using namespace std; #define int long long struct graph{ vector<vector<int> > adi; vector<int> depth; graph(int n){ adi.resize(n); depth.resize(n); } bool dfs(int v, int p, int k, int d){ bool pos=true; int dist1=0; int dist2=0; for(auto u: adi[v]){ if(u==p) continue; pos=pos && dfs(u, v, k, (d+1)%k); if(depth[u]>dist1){ dist2=dist1; dist1=depth[u]; } else{ dist2=max(dist2, depth[u]); } } if(adi[v].size()>2 && d!=0){ if(2*(k-d)+1<=k && dist1>=(k-d) && dist2>=(k-d)){ pos=false; } if(min(k-d-1, dist1)+min(k-d-1, dist2)+1>=k){ pos=false; } } depth[v]=dist1+1; return pos; } }; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; graph g(n); for(int i=0; i<n-1; i++){ int a, b; cin >> a >> b; g.adi[a-1].push_back(b-1); g.adi[b-1].push_back(a-1); } bool pos=false; for(int i=0; i<n; i++){ if(g.dfs(i, -1, k, 0)){ pos=true; } } if(pos){ cout << "YES\n"; } else{ cout << "NO\n"; } cout << 0 << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...