Submission #242558

# Submission time Handle Problem Language Result Execution time Memory
242558 2020-06-28T08:34:40 Z VEGAnn Burza (COCI16_burza) C++14
0 / 160
6 ms 384 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, nw;
int n, k, f[N], ht[N], mx_ht[N], cnt[N], pre[N];

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

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

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

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

        pre[u] = v;

        dfs(u, v);

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

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);

    vc.clear();

    for (int u : g[0])
        if (cnt[u] > 0)
            vc.PB({cnt[u], u});

    for (int it = 0; it < k && sz(vc) > 0; it++){

        sort(all(vc));

        reverse(all(vc));

        nw.clear();

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

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

                if (cnt[u] > 0)
                    nw.PB({cnt[u], u});
            }
        }

        vc = nw;
    }

    cout << (sz(vc) == 0 ? "DA\n" : "NE\n");

    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 4 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 6 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 -