Submission #885273

# Submission time Handle Problem Language Result Execution time Memory
885273 2023-12-09T11:54:53 Z parlimoos Burza (COCI16_burza) C++14
0 / 160
124 ms 1368 KB
//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
1 Incorrect 16 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 124 ms 1204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 109 ms 1024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 109 ms 848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 1368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 972 KB Output isn't correct
2 Halted 0 ms 0 KB -