Submission #914045

# Submission time Handle Problem Language Result Execution time Memory
914045 2024-01-20T22:57:25 Z vjudge1 Burza (COCI16_burza) C++17
160 / 160
501 ms 1780 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MAXN = 405, MAXK = 20, INF = 1e18;
int n, k, cnt, dep[MAXN], mn[MAXN], mx[MAXN], dp[1<<MAXK];
vector<int> adj[MAXN];

void dfs(int x, int p, int d) {
    dep[x] = d;
    if(d==k){
        cnt++;
        mn[x] = mx[x] = cnt;
        return;
    }
    for(int y : adj[x]) {
        if(y==p) continue;
        dfs(y, x, d + 1);
        mn[x] = min(mn[x], mn[y]);
        mx[x] = max(mx[x], mx[y]);
    }
}

signed main() {
    cin.tie(NULL)->sync_with_stdio(0);
    cin>>n>>k;
    if(k>20) {
        cout << "DA\n";
        return 0;
    }
    for(int i = 1; i < n; i++) {
        int x, y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    for(int i = 1; i <= n; i++) {
        mn[i] = INF;
    }
    dfs(1, 0, 0);
    for(int i= 1; i < (1<<k);i++) {
        for(int j = 0;j < k; j++) {
            if((i>>j)&1) {
                int pr = dp[i^(1<<j)];
                for(int  l= 1; l <= n; l++) {
                    if(dep[l]!=j+1)continue;
                    int cmn = mn[l], cmx = mx[l];
                    if(cmn <= pr + 1) {
                        dp[i] = max(dp[i], cmx);
                    }
                }
            }
        }
    }
    for(int i = 1; i < (1<<k); i++) {
        if(dp[i] >= cnt) {
            int counter = 0;
            for(int j = 0; j < k; j++) {
                if((i>>j)&1) counter++;
            }
            if(counter<=k) {
                cout << "DA\n";
                return 0;
            }
        }
    }
    cout << "NE\n";
}
# Verdict Execution time Memory Grader output
1 Correct 40 ms 592 KB Output is correct
2 Correct 478 ms 1364 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 441 ms 1380 KB Output is correct
2 Correct 445 ms 1780 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 440 ms 1368 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 456 ms 1548 KB Output is correct
2 Correct 450 ms 1368 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 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 632 KB Output is correct
2 Correct 462 ms 1380 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 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 429 ms 1392 KB Output is correct
2 Correct 501 ms 1440 KB Output is correct
3 Correct 0 ms 344 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
# Verdict Execution time Memory Grader output
1 Correct 450 ms 1460 KB Output is correct
2 Correct 455 ms 1528 KB Output is correct
3 Correct 1 ms 532 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 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 445 ms 1348 KB Output is correct
2 Correct 442 ms 1360 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 443 ms 1312 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 548 KB Output is correct
2 Correct 459 ms 1488 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
# Verdict Execution time Memory Grader output
1 Correct 34 ms 604 KB Output is correct
2 Correct 486 ms 1368 KB Output is correct
3 Correct 1 ms 344 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
# Verdict Execution time Memory Grader output
1 Correct 187 ms 848 KB Output is correct
2 Correct 456 ms 1376 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 194 ms 1048 KB Output is correct
6 Correct 0 ms 344 KB Output is correct