Submission #407398

# Submission time Handle Problem Language Result Execution time Memory
407398 2021-05-18T21:25:13 Z CrouchingDragon Burza (COCI16_burza) C++17
160 / 160
127 ms 6800 KB
#include "bits/stdc++.h"

using namespace std;

#define endl '\n'
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define all(x) begin(x), end(x)

using ll = long long;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

    int N, K;
    cin >> N >> K;

    if (K * K > N) {
        cout << "DA" << endl;
        exit(0);
    }

    vector<vector<int>> E(N);
    for (int i = 0; i < N - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        E[u].push_back(v), E[v].push_back(u);
    }

    vector<int> h(N), L(N), R(N), V;
    int timer = 0;
    auto dfs = [&](auto&& self, int u, int p) -> void {
        L[u] = timer;
        if (h[u] + 1 < K) {
            for (auto v : E[u]) {
                if (v != p) {
                    h[v] = h[u] + 1;
                    self(self, v, u);
                }
            }
        }
        R[u] = timer++;
        V.push_back(u);
    };
    h[0] = -1;
    dfs(dfs, 0, -1);

    vector<vector<bool>> memo(N);
    vector<bool> dp(1 << K), dpnxt(1 << K);
    dp[0] = true;

    V.pop_back();
    for (auto u : V) {
        for (int mask = 0; mask < (1 << K); ++mask) {
            if (L[u] > 0 && memo[L[u] - 1][mask] && (mask >> h[u] & 1) == 0) {
                dpnxt[mask | 1 << h[u]] = true;
            }
            if (h[u] < K - 1 && dp[mask]) dpnxt[mask] = true;
        }
        if (L[u] == 0) dpnxt[1 << h[u]] = true;

        fill(all(dp), false), swap(dp, dpnxt);
        memo[R[u]] = dp;
    }

    string ans = count(all(dp), true) ? "DA" : "NE";
    cout << ans << endl;

    exit(0);
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 844 KB Output is correct
2 Correct 113 ms 6684 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 6340 KB Output is correct
2 Correct 110 ms 6400 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 118 ms 6620 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 6432 KB Output is correct
2 Correct 111 ms 6360 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1796 KB Output is correct
2 Correct 123 ms 6800 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 6120 KB Output is correct
2 Correct 117 ms 6544 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 6340 KB Output is correct
2 Correct 115 ms 6340 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 6492 KB Output is correct
2 Correct 112 ms 6204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 115 ms 6380 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1612 KB Output is correct
2 Correct 119 ms 6596 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 824 KB Output is correct
2 Correct 127 ms 6588 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 2852 KB Output is correct
2 Correct 122 ms 6556 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 56 ms 2952 KB Output is correct
6 Correct 1 ms 332 KB Output is correct