Submission #436600

#TimeUsernameProblemLanguageResultExecution timeMemory
436600VinnieThePooh32Burza (COCI16_burza)C++14
0 / 160
2 ms352 KiB
#include <iostream> #include <vector> using namespace std; const int N = 405; int n, k; int target = 2; bool rFull = false; vector<int> h, depths; vector<bool> rootChildren; vector<vector<int>> tmpadj, adj; bool dfs(int node, int parent, int depth, int orgNode) { depth++; depths[node] = depth; if (h[node] == k) { rootChildren[orgNode] = true; return true; } bool res = false; for (int v : tmpadj[node]) if (v != parent) { if (node == 1) { orgNode = v; } h[v] = h[node] + 1; int nxt = dfs(v, node, depth, orgNode); res |= nxt; if (nxt) adj[node].push_back(v); } return res; } void dfs2(int node, int parent) { if (depths[node] == target) { target++; return; } if (depths[node] == k + 1 && target == k + 2) { cout << "NE"; rFull = true; return; } for (int v : adj[node]) { if (node == 1 && !rootChildren[v]) { continue; } dfs2(v, node); if (rFull) { return; } } return; } int main() { cin >> n >> k; if (k > 20) { cout << "DA"; } h.resize(n + 1); adj.resize(n + 1); tmpadj.resize(n + 1); depths.resize(n + 1, 0); rootChildren.resize(n + 1); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; tmpadj[u].push_back(v); tmpadj[v].push_back(u); } if (!dfs(1, -1, 0, 0)) { cout << "DA"; } dfs2(1, -1); if (!rFull) { cout << "DA"; } }
#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...