#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, K;
cin >> N >> K;
vector<vector<int>> adj(N);
for (int i = 0; i < N - 1; i++) {
int x, y;
cin >> x >> y;
x--, y--;
adj[x].push_back(y);
adj[y].push_back(x);
}
for (int root = 0; root < N; root++) {
vector<int> c(N);
auto color = [&](auto f, int x, int p, int dep) -> void {
if (dep % K == 0) {
c[x] = 1;
}
for (int y : adj[x]) {
if (y != p) {
f(f, y, x, dep + 1);
}
}
};
color(color, root, -1, 0);
auto dfs = [&](auto dfs, int x, int p, int cnt, int dep) -> bool {
if (dep == K - 1) {
return cnt == 1;
}
for (int y : adj[x]) {
if (y != p) {
if (!dfs(dfs, y, x, cnt + c[y], dep + 1)) {
return 0;
}
}
}
return 1;
};
bool ok = 1;
for (int i = 0; i < N; i++) {
if (!dfs(dfs, i, -1, c[i], 0)) {
ok = 0;
}
}
if (ok) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
return 6/22;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |