Submission #161194

#TimeUsernameProblemLanguageResultExecution timeMemory
161194MinnakhmetovMousetrap (CEOI17_mousetrap)C++14
25 / 100
1103 ms65156 KiB
#include <bits/stdc++.h> #define ll long long #define all(aaa) aaa.begin(), aaa.end() using namespace std; const int N = 1e6 + 5; vector<int> g[N]; int n, m, t; int dfs(int node, int anc) { int adj = g[node].size() - (anc != -1); vector<int> v; for (int to : g[node]) { if (to != anc) { v.push_back(dfs(to, node) + 1); } } sort(v.rbegin(), v.rend()); if (v.empty()) return 0; else if (v.size() == 1) return 1; return v[1] + adj - 1; } signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> t >> m; m--, t--; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--, b--; g[a].push_back(b); g[b].push_back(a); } g[m].erase(find(all(g[m]), t)); cout << dfs(m, -1); 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...