Submission #563700

#TimeUsernameProblemLanguageResultExecution timeMemory
563700hoanghq2004Mousetrap (CEOI17_mousetrap)C++14
25 / 100
694 ms73324 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int n, S, T; vector <int> g[N]; int f[N]; void dfs(int u, int p) { int best[3] = {0, 0, 0}; for (auto v: g[u]) { if (v == p) continue; dfs(v, u); best[2] = f[v]; sort(best, best + 3); reverse(best, best + 3); } f[u] = best[1] + g[u].size() - 1; } int main() { // freopen("mousetrap.inp", "r", stdin); ios :: sync_with_stdio(0); cin.tie(0); cin >> n >> S >> T; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs(T, S); cout << f[T] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...