Submission #885641

# Submission time Handle Problem Language Result Execution time Memory
885641 2023-12-10T10:44:18 Z sanma Burza (COCI16_burza) C++14
160 / 160
153 ms 386184 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)) - 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 300236 KB Output is correct
2 Correct 153 ms 384340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 37 ms 369748 KB Output is correct
6 Correct 7 ms 68188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 367764 KB Output is correct
2 Correct 139 ms 367844 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 149 ms 370008 KB Output is correct
6 Correct 37 ms 384132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 369848 KB Output is correct
2 Correct 147 ms 367780 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 29 ms 295788 KB Output is correct
6 Correct 9 ms 82524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 359532 KB Output is correct
2 Correct 151 ms 386180 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 24 ms 252736 KB Output is correct
6 Correct 6 ms 59992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 353556 KB Output is correct
2 Correct 148 ms 365688 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 375896 KB Output is correct
6 Correct 26 ms 265052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 371976 KB Output is correct
2 Correct 142 ms 361892 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 34 ms 343144 KB Output is correct
6 Correct 21 ms 222044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 375988 KB Output is correct
2 Correct 141 ms 363852 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 137 ms 363680 KB Output is correct
6 Correct 29 ms 299860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 318544 KB Output is correct
2 Correct 145 ms 378076 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 22 ms 222044 KB Output is correct
6 Correct 38 ms 386184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 265040 KB Output is correct
2 Correct 150 ms 378204 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 22 ms 228188 KB Output is correct
6 Correct 33 ms 345168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 314460 KB Output is correct
2 Correct 142 ms 380208 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 92 ms 320648 KB Output is correct
6 Correct 15 ms 158296 KB Output is correct