#include <bits/stdc++.h>
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
bool umn(T& a, T b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
bool umx(T& a, T b) {
return a < b ? a = b, 1 : 0;
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
int add(int a, int b) {
a += b;
if (a >= MOD) {
return a - MOD;
}
return a;
}
int mult(int a, int b) {
return 1LL * a * b % MOD;
}
int n, k;
ve<int> g[N];
int dep[N];
int par[N];
int curRem;
bool have[N];
bool bad;
void dfs(int v = 1, int p = 0) {
par[v] = p;
if (dep[v] % k == 0) {
have[v] = 1;
} else {
have[v] = 0;
}
int cnt = 0;
pii mx = {-1e9, -1e9};
fe (to, g[v]) {
if (to == p) continue;
dep[to] = dep[v] + 1;
dfs(to, v);
have[v] |= have[to];
cnt += have[to];
if (mx.fi < dep[to]) {
mx.se = mx.fi;
mx.fi = dep[to];
} else {
umx(mx.se, dep[to]);
}
}
if (!have[v] && mx.fi + mx.se + 1 >= k) {
bad = 1;
}
if (cnt > 1 && (2 * dep[v]) % k) {
bad = 1;
}
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios::sync_with_stdio(0);
cin.tie(0);
#endif
cin >> n >> k;
fr (i, 1, n - 1) {
int a, b;
cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
}
fr (root, 1, n) {
// cout << "ROOT: " << root << "\n";
bad = 0;
dep[root] = 0;
dfs(root, 0);
if (!bad) {
// cout << "root: " << root << "\n";
cout << "YES\n";
exit(0);
}
}
cout << "NO\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
23764 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
23764 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
23764 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
23764 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |