이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 405
int n, k, rt[N];
vector<int> adj[N];
vector<int> pre[N], suf[N];
int get(int u, int p){
if (rt[u] != -1) return rt[u];
int pos = 0;
int r = 1e18;
if (adj[u].size() == 1 && p != 0) r = 1;
if (adj[u].size() == 0) r = 1;
pre[u][0] = 1;
for (auto x : adj[u]){
if (x == p) continue;
pos++;
pre[u][pos] = max(pre[u][pos - 1], get(x, u) + 1);
}
pos++;
suf[u][pos] = 1;
for (int i = adj[u].size() - 1; i >= 0; i--){
int x = adj[u][i];
if (x == p) continue;
pos--;
suf[u][pos] = max(suf[u][pos + 1], get(x, u) + 1);
}
pos = 0;
for (auto x : adj[u]){
if (x == p) continue;
pos++;
int du = max(pre[u][pos - 1], suf[u][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);
}
for (int i = 0; i <= n; i++) {
pre[i].resize(adj[i].size() + 2, 0);
suf[i].resize(adj[i].size() + 2, 0);
}
if (get(1, 0) <= k){
cout << "DA";
}
else cout << "NE";
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... |