Submission #1025511

# Submission time Handle Problem Language Result Execution time Memory
1025511 2024-07-17T05:48:55 Z wenqi Burza (COCI16_burza) C++17
0 / 160
1 ms 500 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];
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);
                        dfs2(j, i);
                }
        }
}
priority_queue<pair<int, int>> pq[405];
void dfs3(int i) {
        for (int j : eadj[i]) {
                pq[depth[j]].push({-(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;
}

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;
                        }
                }
                dead[k] = true;
        }
        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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 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 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 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 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 500 KB Output is correct
5 Incorrect 0 ms 428 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -