답안 #821277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
821277 2023-08-11T08:38:48 Z Jan636 Burza (COCI16_burza) C++14
0 / 160
244 ms 948 KB
//Bitmask DP Solution
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ms(x, a) memset(x, a, sizeof(x))
const int INF = 0x3f3f3f3f;
//===========================================
const int MAX = 405;
vector<int> adj[MAX];
int dep[MAX], dp[1<<19], l[MAX], r[MAX], curr, n, k;

void dfs(int v, int p){
    if (dep[v] == k){ l[v] = r[v] = ++curr; return; }
    for (int u: adj[v]){
        if (u == p) continue;
        dep[u] = dep[v]+1;
        dfs(u, v);
        l[v] = min(l[v], l[u]);
        r[v] = max(r[v], r[u]);
    }
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> k;
    ms(l, INF); ms(r, 0);
    if (k >= 20){ cout << "NE\n"; return 0; }
    for (int i = 1; i < n; i++){
        int a, b; cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(1, -1);
    for (int mask = 1; mask < 1<<k; mask++){
        dp[mask] = -INF;
        for (int i = 1; i <= n; i++){
            if (!dep[i] || !(mask&(1<<(dep[i]-1)))) continue;
            if (dp[mask^(1<<(dep[i]-1))]+1 >= l[i]) dp[mask] = max({dp[mask], r[i], dp[mask^(1<<(dep[i]-1))]});
        }
    }
    cout << (dp[(1<<k)-1] == curr? "DA\n" : "NE\n");
}
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 340 KB Output is correct
2 Correct 240 ms 828 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 840 KB Output is correct
2 Correct 221 ms 828 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 764 KB Output is correct
2 Correct 228 ms 820 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 392 KB Output is correct
2 Correct 237 ms 828 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 225 ms 820 KB Output is correct
2 Correct 227 ms 756 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 948 KB Output is correct
2 Correct 222 ms 792 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 800 KB Output is correct
2 Correct 223 ms 772 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 376 KB Output is correct
2 Correct 230 ms 768 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 404 KB Output is correct
2 Correct 241 ms 844 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 580 KB Output is correct
2 Correct 231 ms 844 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -