# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
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
# | 결과 | 실행 시간 | 메모리 | 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 | - |
# | 결과 | 실행 시간 | 메모리 | 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 | - |
# | 결과 | 실행 시간 | 메모리 | 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 | - |
# | 결과 | 실행 시간 | 메모리 | 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 | - |