Submission #486048

# Submission time Handle Problem Language Result Execution time Memory
486048 2021-11-10T13:13:16 Z XII Burza (COCI16_burza) C++17
160 / 160
13 ms 4816 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "COCI16_burza"
void Fi(){
    if(fopen(PROB".inp", "r")){
        freopen(PROB".inp", "r", stdin);
        freopen(PROB".out", "w", stdout);
    }
}

void maximize(int &a, const int &b){
    a = (a > b ? a : b);
}

const int INF = 1e9;
const int N = 400 + 1;
const int K = 20;

int n, k, cnt;
int S[N], E[N], h[N];
vector<int> adj[N];
int f[N][N];
int dp[1 << K];

void dfs(int u, int p = 0){
    if(h[u] == k) S[u] = E[u] = ++cnt;
    else S[u] = INF, E[u] = -INF;
    if(h[u] < k) for(int v: adj[u]) if(v != p){
        h[v] = h[u] + 1;
        dfs(v, u);
        S[u] = min(S[u], S[v]);
        E[u] = max(E[u], E[v]);
    }
    if(S[u] != INF) maximize(f[S[u]][h[u]], E[u]);
}

int main(){
    IOS;
    Fi();
    cin >> n >> k;
    if(k * k >= n){ cout << "DA"; return 0; }
    FOR(i, 1, n){
        int u, v; cin >> u >> v;
        adj[u].eb(v), adj[v].eb(u);
    }
    dfs(1);
    if(S[1] == INF){ cout << "DA"; return 0; }
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    FOR(mask, 0, 1 << k) if(dp[mask] != -1 && dp[mask] < E[1]){
        FOR(i, 0, k) if(!(mask & (1 << i))){
            int new_mask = mask | (1 << i);
            maximize(dp[new_mask], f[dp[mask] + 1][i + 1]);
        }
    }
    FOR(mask, 0, 1 << k) if(dp[mask] == E[1]){
        cout << "DA";
        return 0;
    }
    cout << "NE";
    return 0;
}
/// PS: idea stolen :<

Compilation message

burza.cpp: In function 'void Fi()':
burza.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(PROB".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(PROB".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4556 KB Output is correct
2 Correct 9 ms 4556 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 4816 KB Output is correct
6 Correct 2 ms 4428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4584 KB Output is correct
2 Correct 10 ms 4556 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 10 ms 4556 KB Output is correct
6 Correct 3 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4584 KB Output is correct
2 Correct 10 ms 4556 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 2 ms 4684 KB Output is correct
6 Correct 2 ms 4428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4556 KB Output is correct
2 Correct 10 ms 4556 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 4556 KB Output is correct
6 Correct 2 ms 4428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4560 KB Output is correct
2 Correct 10 ms 4556 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 4812 KB Output is correct
6 Correct 2 ms 4684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4580 KB Output is correct
2 Correct 9 ms 4572 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 3 ms 4812 KB Output is correct
6 Correct 2 ms 4556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4556 KB Output is correct
2 Correct 9 ms 4556 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 9 ms 4568 KB Output is correct
6 Correct 2 ms 4684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4684 KB Output is correct
2 Correct 13 ms 4588 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 2 ms 4556 KB Output is correct
6 Correct 2 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4556 KB Output is correct
2 Correct 9 ms 4556 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 4684 KB Output is correct
6 Correct 2 ms 4684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4552 KB Output is correct
2 Correct 10 ms 4556 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 7 ms 4560 KB Output is correct
6 Correct 4 ms 4556 KB Output is correct