답안 #1025524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025524 2024-07-17T06:09:03 Z wenqi Burza (COCI16_burza) C++17
0 / 160
1 ms 600 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;
        if (i == 1) return;
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 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 -
# 결과 실행 시간 메모리 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 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Incorrect 0 ms 344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 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 -