Submission #436639

#TimeUsernameProblemLanguageResultExecution timeMemory
436639VinnieThePooh32Burza (COCI16_burza)C++14
0 / 160
2 ms384 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); adj[v].push_back(node); } } 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 (v != parent) { if (node == 1 && !rootChildren[v]) { continue; } dfs2(v, node); if (rFull) { return; } } return; } void print(vector<vector<int>> a, string name) { cout << name << ": [\n"; for (vector<int> i : a) { cout << " "; for (int j : i) { cout << j << ", "; } cout << "\n"; } cout << "\n]\n"; } void print2(vector<int> a, string name) { cout << name << ": "; for (int i : a) { cout << i << ", "; } } void print3(vector<bool> a, string name) { cout << name << ": "; for (int i : a) { cout << i << ", "; } } 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...