Submission #1025523

# Submission time Handle Problem Language Result Execution time Memory
1025523 2024-07-17T06:07:56 Z wenqi Burza (COCI16_burza) C++17
0 / 160
1000 ms 512 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()

int N, K;
// adj, effective adj
vector<int> adj[405], eadj[405];
int maxdepth[405], depth[405], parents[405], hcnt[405];
int dfs1(int i, int p) {
        maxdepth[i] = depth[i];
        for (int j : adj[i]) {
                if (j == p) continue;
                depth[j] = depth[i] + 1;
                maxdepth[i] = max(maxdepth[i], dfs1(j, i));
        }
        return maxdepth[i];
}
void dfs2(int i, int p) {
        if (depth[i] >= K) return;
        for (int j : adj[i]) {
                if (j == p) continue;
                if (maxdepth[j] >= K) {
                        eadj[i].push_back(j);
                        parents[j] = i;
                        dfs2(j, i);
                }
        }
}
priority_queue<pair<int, int>> pq[405];
void dfs3(int i) {
        for (int j : eadj[i]) {
                pq[depth[j]].push({-(hcnt[i] = (int)adj[i].size()), j});
                dfs3(j);
        }
}

bool dead[405];
bool dfs4(int i) {
        if (depth[i] >= K) return true;
        for (int j : eadj[i]) {
                if (not dead[j] and dfs4(j)) return true;
        }
        return false;
}

void rmrf(int i) {
        dead[i] = true;
        int p = parents[i];
        hcnt[p]--;
        bool saved = false;
        for (int j : eadj[p]) {
                if (not dead[j]) {
                        pq[depth[j]].push({-hcnt[p], j});
                        saved = true;
                }
        }
        if (not saved) rmrf(p);
}

int main(int, const char **) {
        cin.tie(NULL)->sync_with_stdio(false);
        cin >> N >> K;
        for (int i = 1; i < N; i++) {
                int a, b;
                cin >> a >> b;
                adj[a].push_back(b);
                adj[b].push_back(a);
        }
        dfs1(1, 0);
        dfs2(1, 0);
        dfs3(1);
        for (int i = K; i >= 1; i--) {
                int k = 0;
                while (pq[i].size()) {
                        auto [w, j] = pq[i].top();
                        if (not dfs4(j)) {
                                pq[i].pop();
                        } else {
                                k = j;
                                break;
                        }
                }
                if (k and not dead[k]) { rmrf(k); }
        }
        cout << (dfs4(1) ? "NE" : "DA");
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 1087 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 1097 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 1095 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Execution timed out 1100 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 1097 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 1093 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Execution timed out 1094 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 1087 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 1093 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 1094 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -