이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using ii = pair<int, int>;
#define fastIO ios::sync_with_stdio(0); cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define numBit(x) (__builtin_popcountll(1ll * (x)))
#define getBit(x, i) ((x) >> (i) & 1)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        X eps = 1e-9;
        if (x > y + eps) {
            x = y;
            return true;
        } else return false;
    }
template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        X eps = 1e-9;
        if (x + eps < y) {
            x = y;
            return true;
        } else return false;
    }
const int N = 4e2 + 7, oo = 1e9 + 7;
int n, k, m, timer, ans, l[N], r[N], dp[N][1 << 20];
vector<int> adj[N];
void euler(int u, int par = -1, int depth = 0) {
    if (depth == k) {
        l[u] = r[u] = ++timer;
        return;
    }
    for (int v: adj[u]) if (v != par) {
        euler(v, u, depth + 1);
        maximize(r[u], r[v]);
        minimize(l[u], l[v]);
    }
}
void dfs(int u, int par = -1, int depth = 0) {
    if (depth >= k) return;
    for (int v: adj[u]) if (v != par) {
        dfs(v, u, depth + 1);
        if (l[v] == oo) continue;
        for (int i = 0; i < (1 << k); i++) if (!getBit(i, depth))
            dp[r[v]][i | (1 << depth)] |= dp[l[v] - 1][i];
    }
}
signed main() {
    fastIO;
//#ifndef ONLINE_JUDGE
//   freopen("test.inp", "r", stdin);
//   freopen("test.out", "w", stdout);
//#endif
    cin >> n >> k;
    if (k * k >= n) { cout << "DA\n"; return 0; }
    for (int i = 0; i < (1 << k); i++) dp[0][i] = 1;
    for (int i = 1; i <= n; i++) l[i] = oo, r[i] = 0;
    for (int i = 0, u, v; i < n - 1; i++) {
        cin >> u >> v;
        adj[u].pb(v); adj[v].pb(u);
    } euler(1), dfs(1);
    cout << (!dp[timer][(1 << k) - 1] ? "NE" : "DA");
}
/*
dp[i][mask] = can you "block out" of the first i "depth-k" nodes just blocking nodes have depth in "mask"
*/
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |