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;
const int MAXN = 5e3 + 7;
vector<int> G[MAXN];
int dp[MAXN];
int n, k;
void dfs(int v, int p){
int maxu = 0;
for(auto u : G[v]){
if(u == p) continue;
dfs(u, v);
if(dp[u] > dp[maxu]) maxu = u;
}
int maxdp = -1;
for(auto u : G[v]){
if(u == p || u == maxu) continue;
maxdp = max(maxdp, dp[u]);
}
dp[v] = maxdp+1;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 1; i < n; i++){
int a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
dp[0] = -1;
dfs(1, 1);
if(dp[1] < k)
cout << "DA \n";
else cout << "NE \n";
}
# | 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... |