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;
using ll = long long;
#define all(x) x.begin(), x.end()
int N, K;
// adj, effective adj
vector<int> adj[405], eadj[405];
int maxdepth[405], depth[405];
int dfs1(int i, int p) {
maxdepth[i] = depth[i];
for (int j : adj[i]) {
if (j == p) continue;
depth[j] = depth[i] + 1;
maxdepth[i] = max(maxdepth[i], dfs1(j, i));
}
return maxdepth[i];
}
void dfs2(int i, int p) {
if (depth[i] >= K) return;
for (int j : adj[i]) {
if (j == p) continue;
if (maxdepth[j] >= K) {
eadj[i].push_back(j);
dfs2(j, i);
}
}
}
priority_queue<pair<int, int>> pq[405];
void dfs3(int i) {
for (int j : eadj[i]) {
pq[depth[j]].push({-(int)adj[i].size(), j});
dfs3(j);
}
}
bool dead[405];
bool dfs4(int i) {
if (depth[i] >= K) return true;
for (int j : eadj[i]) {
if (not dead[j] and dfs4(j)) return true;
}
return false;
}
bool alldead(int i) {
if (depth[i] >= K) return false;
for (int j : eadj[i])
if (not dead[j]) return false;
return true;
}
int main(int, const char **) {
cin.tie(NULL)->sync_with_stdio(false);
cin >> N >> K;
for (int i = 1; i < N; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs1(1, 0);
dfs2(1, 0);
dfs3(1);
for (int i = K; i >= 1; i--) {
int k = 0;
while (pq[i].size()) {
auto [w, j] = pq[i].top();
if (alldead(j)) {
pq[i].pop();
} else {
k = j;
break;
}
}
dead[k] = true;
}
cout << (dfs4(1) ? "NE" : "DA");
return 0;
}
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |