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
#define N 405
int n, k, rt[N];
vector<int> adj[N];
int get(int u, int p){
if (rt[u] != -1) return rt[u];
vector<int> pre(adj[u].size() + 2, 0);
vector<int> suf(adj[u].size() + 2, 0);
int pos = 0;
int r = n;
if (adj[u].size() == 1 && p != 0) r = 1;
for (auto x : adj[u]){
if (x == p) continue;
pos++;
pre[pos] = max(pre[pos - 1], get(x, u) + 1);
}
pos++;
for (int i = adj[u].size() - 1; i >= 0; i--){
int x = adj[u][i];
if (x == p) continue;
pos--;
suf[pos] = max(suf[pos + 1], get(x, u) + 1);
}
pos = 0;
for (auto x : adj[u]){
if (x == p) continue;
pos++;
int du = max(pre[pos - 1], suf[pos + 1]);
r = min(r, du);
}
return rt[u] = r;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
memset(rt, -1, sizeof(rt));
cin >> n >> k;
for (int i = 1; i <= n - 1; i++){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
if (get(1, 0) <= k){
cout << "DA\n";
}
else cout << "NE\n";
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... |