Submission #1117374

# Submission time Handle Problem Language Result Execution time Memory
1117374 2024-11-23T12:56:18 Z vux2code Burza (COCI16_burza) C++17
160 / 160
40 ms 3336 KB
// Src : Vux2Code
/* Note :
    
*/

#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;

// template <typename T> void vout(T s){ cout << s << endl; exit(0);}

typedef int ll;
typedef long double ld;
typedef pair <ll, ll> pll;

const ll maxN = 4e2 + 5, maxLog = 20;

void maximize (ll &x, ll y) {x = max (x, y);}
void minimize (ll &x, ll y) {x = min (x, y);}

/* ---------HASHING-------- */
// const base = 31, mod2 = 1e9 + 9;

/* ---------BITMASK-------- */
// ll count (ll x) {return __builtin_popcountll (x);}
// ll fst (ll x) {return 63 - __builtin_clzll (x);}
// ll last (ll x) {return __builtin_ctzll (x);}
bool bit (ll x, ll y) {return ((x >> y) & 1);}

ll t = 1;

ll n, k, h [maxN], st [maxN], en [maxN], cnt;
vector <ll> ke [maxN], hvec [maxN];   
bool f [maxN] [1 << maxLog];

void dfs (ll x, ll pr) {
    if (x) h [x] = h [pr] + 1;
    if (h [x] == k - 1) {
        st [x] = cnt ++;
        en [x] = cnt;
        return;
    }
    st [x] = cnt;
    for (ll i : ke [x]) if (i != pr) {
        dfs (i, x);
    }
    en [x] = cnt;
}

bool solve () {
    cin >> n >> k;
    if (k * k >= n) return true;
    for (int i = 1, u, v; i < n; i ++) {
        cin >> u >> v;
        u --; v --;
        ke [u]. push_back (v);
        ke [v]. push_back (u); 
    }
    h [0] = -1;
    dfs (0, -1);
    for (int i = 1; i < n; i ++) hvec [st [i]]. push_back (i);
    f [0] [0] = 1;
    for (int i = 0; i < cnt; i ++) {
        for (int mask = 0; mask < (1 << k); mask ++) {
            if (!f [i] [mask]) continue;
            for (ll j : hvec [i]) {
                if (bit (mask, h [j])) continue;
                f [en [j]] [mask | 1 << h [j]] = 1;
            }
        }
    }
    for (int i = 0; i < (1 << k); i ++) if (f [cnt] [i]) return true;
    return false;
}

int main () {
    ios::sync_with_stdio (0);
    cin. tie (0);
    cout. tie (0);
    #define TASK "task"
    if (fopen (TASK".inp", "r")) {
        freopen (TASK".inp", "r", stdin);
        freopen (TASK".out", "w", stdout);
    }
    // cin >> t;
    while (t --) cout << (solve () ? "DA" : "NE");
}

Compilation message

burza.cpp: In function 'int main()':
burza.cpp:84:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen (TASK".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:85:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen (TASK".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1104 KB Output is correct
2 Correct 25 ms 2544 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 1104 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2888 KB Output is correct
2 Correct 27 ms 2640 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 40 ms 3144 KB Output is correct
6 Correct 2 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2824 KB Output is correct
2 Correct 30 ms 2656 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1360 KB Output is correct
2 Correct 37 ms 3336 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2392 KB Output is correct
2 Correct 31 ms 2908 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2908 KB Output is correct
2 Correct 32 ms 2892 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 1104 KB Output is correct
6 Correct 1 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 3152 KB Output is correct
2 Correct 34 ms 2916 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 508 KB Output is correct
5 Correct 40 ms 3328 KB Output is correct
6 Correct 1 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1360 KB Output is correct
2 Correct 33 ms 2896 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 848 KB Output is correct
6 Correct 1 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 848 KB Output is correct
2 Correct 39 ms 3024 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 848 KB Output is correct
6 Correct 2 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1820 KB Output is correct
2 Correct 36 ms 2888 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 15 ms 1620 KB Output is correct
6 Correct 2 ms 772 KB Output is correct