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;
#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;
depth[v]=0;
for(auto u: adi[v]){
if(u==p) continue;
pos=pos && dfs(u, v, k, (d+1)%k);
if(d!=0 && min(depth[v], k-d)+min(depth[u], k-d)+1>=k){
pos=false;
}
depth[v]=max(depth[v], depth[u]);
}
depth[v]++;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |