Submission #146239

#TimeUsernameProblemLanguageResultExecution timeMemory
146239letrongdatBurza (COCI16_burza)C++17
0 / 160
3 ms1020 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define repn(i, a, b) for(int i=a; i < b; ++i) const int INF = 0x3f3f3f3f; const int N = 410; int n, k; int w[N][N]; vector<int> e[N]; int dfs(int u, int re, int prv = 0) { if (w[u][re] != -1) return w[u][re]; int &ans = w[u][re]; ans = INF; if (re == 0) { if (e[u].size() < 2) return ans = 0; return ans; } if (u == 1) { if (e[u].size() < 1) return ans = 0; } else if (e[u].size() < 3) return ans = 0; multiset < int > ms; for(auto v: e[u]) if (v != prv) ms.insert(dfs(v, re -1, u)); for(auto v: e[u]) if (v != prv) { ms.erase(ms.find(w[v][re-1])); ans = min(ans, *ms.crbegin() + 1); ms.insert(w[v][re-1]); } return ans; } int main() { ios::sync_with_stdio(0); cin >> n >> k; repn(i, 1, n) { int u, v; cin >> u >> v; e[u].pb(v); e[v].pb(u); } memset(w, -1, sizeof w); cout << (dfs(1, k) < k ? "DA" : "NE"); }
#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...