답안 #884643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884643 2023-12-07T20:59:44 Z smax Burza (COCI16_burza) C++17
160 / 160
42 ms 1220 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << "\033[1;35m" << s << "\033[0;32m = \033[33m" << x << "\033[0m\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << "\033[1;35m" << s.substr(0, i) << "\033[0;32m = \033[33m" << x << "\033[31m | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    vector<vector<int>> adj(n);
    for (int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    if (k * k >= n) {
        cout << "DA\n";
        return 0;
    }

    int ti = 0;
    vector<pair<int, int>> cover(n);
    vector<vector<int>> nodes(k);

    auto dfs = [&] (auto &self, int u, int p, int d) -> void {
        if (d == k) {
            ti++;
            cover[u] = {ti, ti};
            nodes[k-1].push_back(u);
            return;
        }
        cover[u] = {INT_MAX, INT_MIN};
        for (int v : adj[u])
            if (v != p) {
                self(self, v, u, d + 1);
                cover[u].first = min(cover[u].first, cover[v].first);
                cover[u].second = max(cover[u].second, cover[v].second);
            }
        if (d > 0 && cover[u].first != INT_MAX)
            nodes[d-1].push_back(u);
    };

    dfs(dfs, 0, -1, 0);

    vector<int> dp(1 << k);
    for (int mask=0; mask<1<<k; mask++) {
        for (int i=0; i<k; i++)
            if (~mask >> i & 1)
                for (int u : nodes[i])
                    if (cover[u].first <= dp[mask] + 1)
                        dp[mask|(1<<i)] = max(dp[mask|(1<<i)], cover[u].second);
        if (dp[mask] == ti) {
            cout << "DA\n";
            return 0;
        }
    }
    cout << "NE\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 33 ms 856 KB Output is correct
3 Correct 0 ms 600 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 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 856 KB Output is correct
2 Correct 31 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 32 ms 860 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 860 KB Output is correct
2 Correct 42 ms 964 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 456 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 604 KB Output is correct
2 Correct 34 ms 860 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 37 ms 1220 KB Output is correct
2 Correct 31 ms 1056 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 860 KB Output is correct
2 Correct 31 ms 860 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 860 KB Output is correct
2 Correct 31 ms 860 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 32 ms 860 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 604 KB Output is correct
2 Correct 32 ms 860 KB Output is correct
3 Correct 1 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 4 ms 344 KB Output is correct
2 Correct 32 ms 860 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 604 KB Output is correct
2 Correct 32 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 17 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct