Submission #570070

#TimeUsernameProblemLanguageResultExecution timeMemory
570070jesus_coconutMousetrap (CEOI17_mousetrap)C++17
25 / 100
789 ms69440 KiB
#include <bits/stdc++.h> #define pb push_back #define all(a) begin(a), end(a) using namespace std; int const N = 1000005; int n, t, m; vector<vector<int>> adj; int st = 0; void load() { cin >> n >> t >> m; --t; --m; adj.resize(n); for (int i = 0; i < n - 1; ++i) { int u, v; cin >> u >> v; --u; --v; adj[u].pb(v); adj[v].pb(u); } for (auto u : adj[t]) { if (u == m) { st = 2; } } } int dfs(int ver, int par) { int ans = adj[ver].size() - 1; vector<int> tmp; for (auto u : adj[ver]) if (u != par) { tmp.pb(dfs(u, ver)); } sort(all(tmp), greater<>()); if (size(tmp) >= 2) { ans += tmp[1]; } return ans; } void solve() { assert(st == 2); cout << dfs(m, t) << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); load(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...