Submission #537322

#TimeUsernameProblemLanguageResultExecution timeMemory
537322MinhAnhndBurza (COCI16_burza)C++14
0 / 160
1 ms360 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...