# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
680289 | 2023-01-10T13:42:26 Z | mjhmjh1104 | Wells (CEOI21_wells) | C++17 | 22 ms | 35412 KB |
#include <cstdio> #include <vector> #include <utility> #include <algorithm> using namespace std; int n, k; vector<int> adj[1500006]; pair<int, int> dfs(int x, int prev = -1) { pair<int, int> res = { 0, 0 }; vector<int> v; for (auto &i: adj[x]) if (i != prev) { pair<int, int> curr = dfs(i, x); res.first += curr.first; res.second = max(res.second, curr.second + 1); v.push_back(curr.second + 1); } bool fl = false; int curr = 0; if (!v.empty()) { swap(v.back(), *max_element(v.begin(), v.end())); curr += v.back(); v.pop_back(); } if (!v.empty()) { swap(v.back(), *max_element(v.begin(), v.end())); curr += v.back(); v.pop_back(); } if (curr >= k) fl = true; if (fl) res.first++, res.second = -1; return res; } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n - 1; i++) { int u, v; scanf("%d%d", &u, &v); u--, v--; adj[u].push_back(v); adj[v].push_back(u); } int res = 0; for (int i = 0; i < n; i++) res = max(res, (int)adj[i].size()); if (res <= 2 || k == 1) return puts("YES\n1"), 0; k--; if (dfs(0).first >= 2) puts("NO\n0"); else puts("YES\n1"); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Partially correct | 22 ms | 35412 KB | Output is partially correct |
2 | Incorrect | 17 ms | 35412 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Partially correct | 22 ms | 35412 KB | Output is partially correct |
2 | Incorrect | 17 ms | 35412 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Partially correct | 22 ms | 35412 KB | Output is partially correct |
2 | Incorrect | 17 ms | 35412 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Partially correct | 22 ms | 35412 KB | Output is partially correct |
2 | Incorrect | 17 ms | 35412 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |