Submission #551970

# Submission time Handle Problem Language Result Execution time Memory
551970 2022-04-22T04:35:32 Z aadit_ambadkar Burza (COCI16_burza) C++11
48 / 160
81 ms 2792 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> adj[402], q[402];
int n, k, st[402], dr[402], level[402], pz;

void dfs(int u, int p) {
    if (u==p) return;
    if (u) {
        level[u]=level[p]+1;
    }
    if (level[u]==k-1) {
        st[u]=pz++;
        dr[u]=pz;
    }
    st[u]=pz;
    for (auto i : adj[u]) {
        if (i!=p) dfs(i, u);
    }
    dr[u]=pz;
}

bool dp[402][(1<<20)];

bool solve() {
    dp[0][0]=1;
    for (int i = 1; i < n; i++) {
        q[st[i]].push_back(i);
    }
    for (int i = 0; i < pz; i++) {
        for (int j = 0; j < (1<<k); j++) {
            if (!dp[i][j]) continue;
            for (auto it : q[i]) {
                if (!(j >> level[it] & 1)) {
                    dp[dr[it]][j | (1<<level[it])]=1;
                }
            }
        }
    }
    for (int j = 0; j < (1<<k); j++) {
        if (dp[pz][j]) return 1;
    }
    return 0;
}

int main() {
    cin >> n >> k;
    if (k*k >= n) {
        cout << "DA\n";
        return 0;
    }
    for (int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    level[0]=-1;
    dfs(0, -1);
    cout << (solve() ? "DA\n" : "NE\n");
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 852 KB Output is correct
2 Correct 70 ms 2504 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 81 ms 2524 KB Output is correct
2 Correct 63 ms 2464 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 76 ms 2336 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 2520 KB Output is correct
2 Correct 68 ms 2508 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1108 KB Output is correct
2 Correct 59 ms 2580 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 724 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 2336 KB Output is correct
2 Correct 53 ms 2484 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 852 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 2336 KB Output is correct
2 Correct 57 ms 2508 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 1108 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 2616 KB Output is correct
2 Correct 61 ms 2380 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 71 ms 2792 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1100 KB Output is correct
2 Correct 64 ms 2352 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 732 KB Output is correct
2 Correct 76 ms 2488 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 596 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1420 KB Output is correct
2 Correct 73 ms 2768 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 29 ms 1652 KB Output isn't correct
6 Halted 0 ms 0 KB -