Submission #1175895

#TimeUsernameProblemLanguageResultExecution timeMemory
1175895InvMODBurza (COCI16_burza)C++20
0 / 160
14 ms1864 KiB
#include<bits/stdc++.h> using namespace std; #define all(v) (v).begin(), (v).end() void solve() { int n,k; cin >> n >> k; vector<vector<int>> adj(n + 1, vector<int>()); for(int i = 0; i < n - 1; i++){ int u,v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } if(k * k >= n){ // each h should has >= k element to counter Daniel cout << "DA\n"; return; } int cntLose = 0; vector<int> tin(n + 1), tout(n + 1), h(n + 1); vector<vector<int>> cover(n + 1, vector<int>()); function<void(int,int)> dfs = [&](int x, int p) -> void{ if(h[x] >= k - 1){ tin[x] = tout[x] = cntLose++; cover[tin[x]].push_back(x); } else{ tin[x] = tout[x] = n + 1; for(int v : adj[x])if(v != p){ h[v] = h[x] + 1; dfs(v, x); tin[x] = min(tin[x], tin[v]); tout[x] = max(tout[x], tout[v]); } if(x != 1 && tin[x] <= n) cover[tin[x]].push_back(x); } }; h[1] = -1; dfs(1, -1); /* + with each height we can only choose 1 element + choose an element x will cover form [tin[x] -> tout[x]] */ vector<vector<int>> dp(2, vector<int>((1 << k), -1)); dp[0][0] = 0; for(int i = 0; i < cntLose; i++){ for(int mask = (1 << k) - 1; mask >= 0; mask--){ if(dp[0][mask] >= i){ for(int x : cover[i]){ assert(h[x] >= 0 && h[x] < k); if(mask >> h[x] & 1) continue; dp[1][mask | (1 << h[x])] = max(dp[1][mask | (1 << h[x])], max(dp[0][mask], tout[x] + 1)); } } } swap(dp[0], dp[1]); for(int mask = 0; mask < (1 << k); mask++) dp[1][mask] = -1; } cout << (*max_element(all(dp[0])) >= cntLose ? "DA" : "NE") << "\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

burza.cpp: In function 'int32_t main()':
burza.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...