This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'
int n , k;
vector<int> tr[400];
int dp[400][401];
void f(int v = 0 , int p = -1 , int lm = k){
for(int u : tr[v]){
if(u != p){
f(u , v , lm);
if(lm > 0) f(u , v , lm - 1);
}
}
if(v != 0 and (int)tr[v].size() == 1) dp[v][lm] = 0;
if(lm == 0){
dp[v][lm] = -1;
for(int u : tr[v]){
if(u != p){
dp[v][lm] = max(dp[v][lm] , dp[u][lm]);
}
}
dp[v][lm]++;
}else if((v == 0 and (int)tr[v].size() == 1) or (v != 0 and (int)tr[v].size() == 2)){
dp[v][lm] = 0;
}else{
int mxs[2] = {-1 , -1};
for(int u : tr[v]){
if(u != p){
if(mxs[0] == -1 or mxs[0] < dp[u][lm - 1]){
mxs[1] = mxs[0];
mxs[0] = dp[u][lm - 1];
}else if(mxs[1] == -1 or mxs[1] < dp[u][lm - 1]){
mxs[1] = dp[u][lm - 1];
}
}
}
int res1 = mxs[1];
int res2 = -1;
for(int u : tr[v]){
if(u != p){
res2 = max(res2 , dp[u][lm]);
}
}
dp[v][lm] = min(res1 , res2) + 1;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 1 ; i < n ; i++){
int v , u;
cin >> v >> u;
v-- , u--;
tr[v].pb(u) , tr[u].pb(v);
}
f();
if(dp[0][k] >= k) cout << "NE";
else cout << "DA";
}
# | 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... |