Submission #961189

#TimeUsernameProblemLanguageResultExecution timeMemory
961189imannBurza (COCI16_burza)C++17
0 / 160
1 ms452 KiB
#include <iostream> #include <map> #include <vector> #include <array> #include <queue> #include <set> const int MAX_N = 400 + 2; std::array<std::vector<int>, MAX_N> graph; std::array<std::vector<int>, MAX_N> children; std::map<int, int> toParent; std::map<int, bool> color; std::array<int, MAX_N> dp; void bfs() { std::queue<int> q; q.push(1); color[1] = true; while (!q.empty()) { int n = q.front(); q.pop(); color[n] = true; for (int c : graph[n]) { if (!color[c]) { children[n].push_back(c); toParent[c] = n; q.push(c); } } } } int solve(int n) { bfs(); std::set<int> nexts; for (int i = 1; i <= n; ++i) { if (children[i].size() == 0 && toParent[i] != 0) { nexts.insert(toParent[i]); } } while (!nexts.empty()) { std::set<int> nNexts; for (int n : nexts) { int max = -1, nmax = -1; for (int c : children[n]) { if (dp[c] > max) { nmax = max; max = dp[c]; } else if (dp[c] > nmax) { nmax = dp[c]; } } dp[n] = nmax + 1; if (toParent[n] != 0) nNexts.insert(toParent[n]); } nexts = nNexts; } return dp[1]; } int main() { int n, k; std::cin >> n >> k; for (int i = 0; i < n - 1; ++i) { int a, b; std::cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } if (k <= solve(n)) { std::cout << "NE" << std::endl; } else { std::cout << "DA" << std::endl; } }
#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...