Submission #626725

#TimeUsernameProblemLanguageResultExecution timeMemory
626725MilosMilutinovicBurza (COCI16_burza)C++14
0 / 160
115 ms237932 KiB
/** * author: wxhtzdy * created: 11.08.2022 18:52:59 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<vector<int>> g(n); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; --u; --v; g[u].push_back(v); g[v].push_back(u); } vector<int> dep(n); vector<int> dfn(n); vector<int> dfo(n); int T = 0; function<void(int, int)> Dfs = [&](int v, int pr) { dfn[v] = ++T; for (int u : g[v]) { if (u == pr) { continue; } dep[u] = dep[v] + 1; Dfs(u, v); } dfo[v] = ++T; }; Dfs(0, 0); if (*max_element(dep.begin(), dep.end()) < k) { cout << "DA" << '\n'; return 0; } vector<vector<int>> at(n); for (int i = 0; i < n; i++) { at[dep[i]].push_back(i); } for (int i = 0; i < n; i++) { sort(at[i].begin(), at[i].end(), [&](int u, int v) { return dfn[u] < dfn[v]; }); } auto isPar = [&](int v, int u) { return dfn[v] <= dfn[u] && dfo[u] <= dfo[v]; }; vector<vector<vector<int>>> can(n, vector<vector<int>>(n, vector<int>(n, -1))); function<bool(int, int, int)> Solve = [&](int l, int r, int dep) { if (can[l][r][dep] != -1) { return can[l][r][dep] == 1; } can[l][r][dep] = 0; for (int v : at[dep]) { int L = 0, R = 0; { int low = 0, high = at[k].size() - 1; while (low <= high) { int mid = low + high >> 1; if (isPar(v, at[k][mid])) { L = mid; high = mid - 1; } else { if (dfn[v] > dfn[at[k][mid]]) { low = mid + 1; } else { high = mid - 1; } } } } { int low = 0, high = at[k].size() - 1; while (low <= high) { int mid = low + high >> 1; if (isPar(v, at[k][mid])) { R = mid; low = mid + 1; } else { if (dfn[v] > dfn[at[k][mid]]) { low = mid + 1; } else { high = mid - 1; } } } } if (!isPar(v, at[k][L])) { continue; } bool ok = true; if (L > l) { ok &= Solve(l, L - 1, dep + 1); } if (R < r) { ok &= Solve(R + 1, r, dep + 1); } if (ok) { can[l][r][dep] = 1; } } return can[l][r][dep] == 1; }; cout << (Solve(0, (int) at[k].size() - 1, 1) ? "DA" : "NE") << '\n'; return 0; }

Compilation message (stderr)

burza.cpp: In lambda function:
burza.cpp:65:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |           int mid = low + high >> 1;
      |                     ~~~~^~~~~~
burza.cpp:81:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   81 |           int mid = low + high >> 1;
      |                     ~~~~^~~~~~
#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...