Submission #885640

# Submission time Handle Problem Language Result Execution time Memory
885640 2023-12-10T10:42:18 Z sanma Burza (COCI16_burza) C++14
64 / 160
104 ms 386136 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] = v.size();
    v.push_back(x);
    for(auto y : a[x]){
        if(y != pX && maxf[y] == k){
            dfs(y, x);
        }
    }
    tout[x] = v.size();
}

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[v.size()][i] = 1;
    for(int i = v.size() - 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 41 ms 299856 KB Output is correct
2 Correct 98 ms 384336 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 369748 KB Output is correct
6 Incorrect 7 ms 68184 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 367900 KB Output is correct
2 Correct 103 ms 367900 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 93 ms 369888 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 369788 KB Output is correct
2 Correct 91 ms 367740 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 29 ms 295728 KB Output is correct
6 Correct 8 ms 82524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 359528 KB Output is correct
2 Correct 98 ms 386136 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 25 ms 252764 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 89 ms 353452 KB Output is correct
2 Correct 92 ms 365812 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 35 ms 375900 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 97 ms 371792 KB Output is correct
2 Correct 94 ms 361528 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 34 ms 343012 KB Output is correct
6 Correct 22 ms 222036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 375936 KB Output is correct
2 Correct 90 ms 363800 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 363584 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 318472 KB Output is correct
2 Correct 104 ms 378036 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 22 ms 222068 KB Output is correct
6 Correct 37 ms 386132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 265092 KB Output is correct
2 Correct 96 ms 377940 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 22 ms 228204 KB Output is correct
6 Correct 35 ms 345064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 314356 KB Output is correct
2 Correct 95 ms 380192 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 62 ms 320492 KB Output isn't correct
6 Halted 0 ms 0 KB -