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>
#include <iostream>
#define ll long long
#define ull unsigned ll
using namespace std;
vector<long> branches[401];
vector<long> children[401];
long parents[401];
long N,K;
long dp[401]={};
long depth = -1;
void dfs(long u,long parent){
depth++;
parents[u] = parent;
for (auto v:branches[u]){
if (v!=parent){
children[u].push_back(v);
dfs(v,u);
}
}
if (depth==K){
dp[u] = LONG_MAX;
}
else if (children[u].size()<2){
dp[u] = 0;
}
else{
//sort(children[u].begin(),children[u].end(),greater<>());
for (auto v:children[u]){
if (dp[v] != 0) dp[u]++;
}
if (dp[u]!=0) dp[u]--;
}
depth--;
return;
}
int main(){
cin>>N>>K;
for(long i = 1;i<=N-1;i++){
long u,v;
cin>>u>>v;
branches[u].push_back(v);
branches[v].push_back(u);
}
dfs(1,-1);
if (dp[1] == 0) cout<<"DA"; else cout<<"NE";
}
# | 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... |