Submission #830081

#TimeUsernameProblemLanguageResultExecution timeMemory
830081t6twotwoMousetrap (CEOI17_mousetrap)C++17
25 / 100
914 ms101504 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, t, m; cin >> N >> t >> m; t--, m--; vector<vector<int>> adj(N); for (int i = 0; i < N - 1; i++) { int x, y; cin >> x >> y; x--, y--; adj[x].push_back(y); adj[y].push_back(x); } vector<int> p(N, -1); queue<int> q; p[m] = m; q.push(m); while (!q.empty()) { int x = q.front(); q.pop(); for (int y : adj[x]) { if (p[y] == -1) { p[y] = x; q.push(y); } } } vector<int> path{t}; while (path.back() != m) { path.push_back(p[path.back()]); } vector<bool> in(N); for (int x : path) { in[x] = 1; } vector<int> f(N); auto dfs = [&](auto dfs, int x, int p) -> void { vector<int> s; for (int y : adj[x]) { if (y == p || in[y]) { continue; } dfs(dfs, y, x); s.push_back(f[y]); } sort(s.rbegin(), s.rend()); if (s.empty()) { return; } if (s.size() == 1) { f[x] = 1; return; } f[x] = s[1] + s.size(); }; vector<vector<int>> ch(N); for (int x : path) { for (int y : adj[x]) { if (!in[y]) { ch[x].push_back(y); } } dfs(dfs, x, -1); } cout << f[path[1]] << "\n"; return 6/22; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...