Submission #467206

#TimeUsernameProblemLanguageResultExecution timeMemory
467206BeanZBurza (COCI16_burza)C++14
160 / 160
14 ms1484 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 405; long long mod = 1e9 + 7; const int lim = 4e5 + 5; const int lg = 21; const int base = 37; const long double eps = 1e-6; ll tin[N], tout[N], par[N][21], in[N], dp[(1 << 21)]; ll timer = 0; vector<ll> node[N]; ll k; void dfs(ll u, ll p, ll d){ bool flag = false; tin[u] = 1e9; tout[u] = 0; for (auto j : node[u]){ if (j == p) continue; for (int i = 1; i <= k; i++){ par[j][i] = par[u][i]; } if ((d + 1) <= k) par[j][d + 1] = j; dfs(j, u, d + 1); tin[u] = min(tin[u], tin[j]); tout[u] = max(tout[u], tout[j]); flag = true; } if ((d == k) && u != 1){ timer++; tin[u] = timer; tout[u] = timer; in[timer] = u; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("tests.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n; cin >> n >> k; for (int i = 1; i < n; i++){ ll u, v; cin >> u >> v; node[u].push_back(v); node[v].push_back(u); } if ((k * k) >= n) return cout << "DA", 0; dfs(1, 1, 0); dp[0] = 0; for (int i = 1; i < (1 << k); i++){ for (int j = 0; j < k; j++){ if (i & (1 << j)){ ll id = dp[i ^ (1 << j)]; dp[i] = max(dp[i], id); id++; dp[i] = max(dp[i], tout[par[in[id]][j + 1]]); } } } if (dp[(1 << k) - 1] == timer) cout << "DA"; else cout << "NE"; } /* 6 2 1 2 2 3 3 4 1 5 5 6 Ans: Out: */

Compilation message (stderr)

burza.cpp: In function 'void dfs(long long int, long long int, long long int)':
burza.cpp:16:10: warning: variable 'flag' set but not used [-Wunused-but-set-variable]
   16 |     bool flag = false;
      |          ^~~~
burza.cpp: In function 'int main()':
burza.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
burza.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen("test.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...