Submission #1116922

# Submission time Handle Problem Language Result Execution time Memory
1116922 2024-11-22T14:54:39 Z vux2code Burza (COCI16_burza) C++17
0 / 160
4 ms 760 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 long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

const ll maxN = 20, maxLog = 20, inf64 = 1e18, inf32 = 1e9, mod = 1e9 + 7;

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;   
ll k;
vector<int> tree[maxN];
vector<int> nodesAtDepth[maxN];
int discovery[maxN], finish[maxN], depth[maxN];
char dp[maxN][1 << maxLog];
int timeCounter = 0;

void dfs(int node, int parent) {
    if (node != 0) depth[node] = depth[parent] + 1;
    
    if (depth[node] == k - 1) {
        discovery[node] = timeCounter++;
        finish[node] = timeCounter;
        return;
    }
    
    discovery[node] = timeCounter;
    
    for (int neighbor : tree[node]) {
        if (neighbor != parent) dfs(neighbor, node);
    }
    
    finish[node] = timeCounter;
}

bool canWin() {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    
    for (int i = 1; i < n; i++) {
        nodesAtDepth[discovery[i]].push_back(i);
    }
    
    for (int time = 0; time < timeCounter; time++) {
        for (int mask = 0; mask < (1 << k); mask++) {
            if (!dp[time][mask]) continue;
            
            for (int node : nodesAtDepth[time]) {
                if (!(mask & (1 << depth[node]))) {
                    dp[finish[node]][mask | (1 << depth[node])] = 1;
                }
            }
        }
    }
    
    for (int mask = 0; mask < (1 << k); mask++) {
        if (dp[timeCounter][mask]) return true;
    }
    return false;
}

void readInput() {
    cin >> n >> k;
    
    if (k * k >= n) {
        cout << "DA\n";
        exit(0);
    }
    
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
}
    

void solve () {
    
    // cin >> n >> k;
    readInput();
    depth[0] = -1;
    dfs(0, -1);
    cout << (canWin() ? "DA" : "NE") << "\n";
}

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 --) solve ();
}

Compilation message

burza.cpp: In function 'int main()':
burza.cpp:120:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |         freopen (TASK".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:121:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  121 |         freopen (TASK".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 760 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 760 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -