Submission #242550

# Submission time Handle Problem Language Result Execution time Memory
242550 2020-06-28T07:49:08 Z VEGAnn Burza (COCI16_burza) C++14
0 / 160
6 ms 512 KB
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define i2 array<int,2>
using namespace std;
const int N = 510;
const int oo = 2e9;
vector<int> g[N];
vector<i2> vc;
int n, k, f[N], ht[N], mx_ht[N];

void dfs(int v, int pr){
    mx_ht[v] = ht[v];

    if (ht[v] == k){
        f[v] = oo;
        return;
    }

    for (int u : g[v]){
        if (u == pr) return;

        ht[u] = ht[v] + 1;

        dfs(u, v);

        mx_ht[v] = max(mx_ht[v], mx_ht[u]);
    }

    if (mx_ht[v] < k){
        f[v] = 0;
        return;
    }

    vc.clear();

    for (int u : g[v]){
        if (u == pr) continue;

        if (f[u] > 0)
            vc.PB({f[u], u});
    }

    f[v] = 1;

    sort(all(vc));

    for (int it = 1; it < sz(vc); it++){
        i2 cur = vc[it];

        if (cur[0] == oo) {
            f[v] = oo;
            break;
        }

        f[v] += cur[0];
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> k;

    for (int i = 1; i < n; i++){
        int x, y; cin >> x >> y;

        x--; y--;

        g[x].PB(y);
        g[y].PB(x);
    }

    dfs(0, -1);

    cout << (f[0] > k ? "NE" : "DA");

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -