답안 #926565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926565 2024-02-13T09:46:36 Z MinaRagy06 Burza (COCI16_burza) C++17
160 / 160
48 ms 1112 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 405;
vector<int> adj[N];
int par[N], dep[N], t;
array<int, 2> v[N];
int n, k;
vector<int> gud[N];
void dfs(int i, int p, int d) {
    for (auto nxt : adj[i]) {
        if (nxt == p) continue;
        dfs(nxt, i, d + 1);
        v[i][0] = min(v[i][0], v[nxt][0]);
        v[i][1] = max(v[i][1], v[nxt][1]);
    }
    dep[i] = d;
    if (d == k) {
        v[i][0] = min(v[i][0], t);
        v[i][1] = max(v[i][1], t);
        t++;
    }
    if (v[i][0] != n + 1) {
        par[i] = p;
        gud[d].push_back(i);
    }
}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n >> k;
    if (n <= k * k) {
        cout << "DA\n";
        return 0;
    }
    for (int i = 1, u, v; i < n; i++) {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        v[i] = {n + 1, -1};
    }
    dfs(1, 0, 0);
    for (int i = 1; i <= n; i++) adj[i].clear();
    for (int i = 1; i <= n; i++) {
        if (!par[i]) continue;
        adj[par[i]].push_back(i);
    }
    // for (int i = 1; i <= k; i++) {
    //     for (auto j : gud[i]) {
    //         cout << v[j][0] << ", " << v[j][1] << '\n';
    //     }
    //     cout << '\n';
    // }
    int m = 1 << k, dp[m];
    dp[0] = -1;
    for (int msk = 1; msk < m; msk++) {
        dp[msk] = -1;
        for (int j = 1; j <= k; j++) {
            if (!((msk >> (j - 1)) & 1)) continue;
            for (auto i : gud[j]) {
                if (v[i][0] <= dp[msk ^ (1 << (j - 1))] + 1) {
                    dp[msk] = max(dp[msk], v[i][1]);
                }
            }
        }
    }
    if (dp[m - 1] == t - 1) {
        cout << "DA\n";
    } else {
        cout << "NE\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 45 ms 1016 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 860 KB Output is correct
2 Correct 43 ms 988 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 43 ms 860 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 860 KB Output is correct
2 Correct 45 ms 1104 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 492 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 600 KB Output is correct
2 Correct 45 ms 856 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1112 KB Output is correct
2 Correct 44 ms 856 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 860 KB Output is correct
2 Correct 46 ms 860 KB Output is correct
3 Correct 0 ms 544 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 860 KB Output is correct
2 Correct 42 ms 856 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 42 ms 860 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 604 KB Output is correct
2 Correct 44 ms 860 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 45 ms 1012 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 604 KB Output is correct
2 Correct 45 ms 856 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 20 ms 752 KB Output is correct
6 Correct 0 ms 348 KB Output is correct