#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-1)+min(depth[u], k-d-1)+1!=k-1){
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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Output is partially correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |