Submission #885638

# Submission time Handle Problem Language Result Execution time Memory
885638 2023-12-10T10:40:56 Z sanma Burza (COCI16_burza) C++14
64 / 160
95 ms 386148 KB
//                  -----------------------------------------------------------------------------------------------------
//                  |                                                                                                   |
//                  |     ngungungu            ngungungu            ngu ngu ngungu        ngungungu       ngungungu     |
//                  |      ngu ngu nguu         ngu ngu         ngu ngu nguuu nguuu        ngu ngu         ngu ngu      |
//                  |      ngu ngu  nguu        ngu ngu        ngu ngu         nguuu       ngu ngu         ngu ngu      |
//                  |      ngu ngu   nguu       ngu ngu       ngu ngu          nguuu       ngu ngu         ngu ngu      |
//                  |      ngu ngu    nguu      ngu ngu       ngu ngu                      ngu ngu         ngu ngu      |
//                  |      ngu ngu     nguu     ngu ngu       ngu ngu                      ngu ngu         ngu ngu      |
//                  |      ngu ngu      nguu    ngu ngu       ngu ngu                      ngu ngu         ngu ngu      |
//                  |      ngu ngu       nguu   ngu ngu       ngu ngu        ngungungu      ngu ngu       ngu ngu       |
//                  |      ngu ngu        nguu  ngu ngu        ngu ngu         nguuu        ngu ngu       ngu ngu       |
//                  |      ngu ngu         nguu ngu ngu        ngu ngu ngu ngu nguuu         ngu ngu ngu ngu ngu        |
//                  |     ngungungu            ngungungu          ngu ngu ngu ngu              ngu ngu ngu ngu          |
//                  |                                                                                                   |
//                  -----------------------------------------------------------------------------------------------------

// ONLINE_JUDGE

#include<bits/stdc++.h>
#define f(i,a,b) for(int i = (a) , _b = (b) ; i <= _b ;i ++)
#define F first
#define S second
//#define int long long
#define pii pair<int, int>
#define piii pair<int, pair<int, int>>
#define piiii pair<pair<int, int>, pair<int, int>>
#define minimize(x,y) x = (x > y ? y : x)
#define maximize(x,y) x = (x < y ? y : x)

using namespace std;

const int maxn = 409;
const int mod = 1e9 + 7;

int n, k;
vector<int> a[maxn];
int h[maxn], maxf[maxn];
int tin[maxn], tout[maxn], timef;
vector<int> v;
bool dp[maxn][(1 << 20) + 1];

void pre(int x, int pX){
    maxf[x] = h[x];
    if(h[x] == k) return;
    for(auto y : a[x]){
        if(y != pX){
            h[y] = h[x] + 1;
            pre(y, x);
            maximize(maxf[x], maxf[y]);
        }
    }
}

void dfs(int x, int pX){
    tin[x] = timef ++;
    v.push_back(x);
    for(auto y : a[x]){
        if(y != pX && maxf[y] == k){
            dfs(y, x);
        }
    }
    tout[x] = timef;
}

int32_t main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    f(i, 1, n - 1){
        int u, v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    if(k >= 20){
        cout << "DA";
        return 0;
    }
    pre(1, 0);
    dfs(1, 0);
    f(i, 0, (1 << 20) - 1) dp[timef][i] = 1;
    for(int i = timef - 1;i >= 0;i --){
        f(j, 0, (1 << k) - 1){
            int x = v[i];
            if(h[x] < k){
                dp[i][j] = dp[i + 1][j];
                if(dp[i][j]) continue;
            }
            if((j >> h[x]) & 1) continue;
            dp[i][j] = dp[tout[x]][j | (1 << h[x])];
        }
    }
    cout << (dp[1][0] ? "DA" : "NE");

}
# Verdict Execution time Memory Grader output
1 Correct 39 ms 299860 KB Output is correct
2 Correct 94 ms 384084 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 37 ms 369784 KB Output is correct
6 Incorrect 7 ms 68440 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 90 ms 367900 KB Output is correct
2 Correct 92 ms 367664 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 90 ms 369956 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 369744 KB Output is correct
2 Correct 94 ms 367768 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 29 ms 295772 KB Output is correct
6 Correct 8 ms 82520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 359508 KB Output is correct
2 Correct 95 ms 386148 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 24 ms 252764 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 353364 KB Output is correct
2 Correct 90 ms 365856 KB Output is correct
3 Correct 1 ms 548 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 36 ms 375892 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 90 ms 371844 KB Output is correct
2 Correct 88 ms 361552 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 33 ms 343128 KB Output is correct
6 Correct 23 ms 222044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 375900 KB Output is correct
2 Correct 89 ms 363604 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 89 ms 363564 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 42 ms 318480 KB Output is correct
2 Correct 93 ms 378156 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 21 ms 221916 KB Output is correct
6 Correct 37 ms 386064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 265052 KB Output is correct
2 Correct 93 ms 378136 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 22 ms 228188 KB Output is correct
6 Correct 33 ms 345172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 314456 KB Output is correct
2 Correct 94 ms 380132 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 55 ms 320592 KB Output isn't correct
6 Halted 0 ms 0 KB -