Submission #872623

#TimeUsernameProblemLanguageResultExecution timeMemory
872623vjudge1Mousetrap (CEOI17_mousetrap)C++17
0 / 100
244 ms55084 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define ONLINE_JUDGE void solve() { int n, t, m; cin >> n >> t >> m; if(m == t) { cout << 0 << "\n"; return; } vector <int> adj[n +1]; for(int i = 1; i <= n -1; i++) { int u, v; cin >> u >> v; adj[u].emplace_back(v); adj[v].emplace_back(u); } function <int(int, int)> dfs = [&](int node, int par) -> int { //cerr << node << " " << par << "\n"; vector <int> chills; for(int child : adj[node]) { if(child == par) { continue; } chills.emplace_back(dfs(child, node) +2); } sort(chills.begin(), chills.end(), greater <> ()); if(int(chills.size()) <= 1) { return 0; } //cerr << node << " " << par << " :: " << chills[1] << " " << int(chills.size()) << "\n"; return chills[1] + int(chills.size()) -1; }; cout << dfs(m, t) +1; return; } signed main() { #ifndef ONLINE_JUDGE freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; for(int i = 1; i <= t; i++) { 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...