Submission #570826

#TimeUsernameProblemLanguageResultExecution timeMemory
570826ShinMousetrap (CEOI17_mousetrap)C++14
0 / 100
303 ms78488 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define all(x) x.begin(), x.end() using namespace std; template <class X, class Y> bool minimize(X &a, Y b) { if (a > b) return a = b, true; return false; } template <class X, class Y> bool maximize(X &a, Y b) { if (a < b) return a = b, true; return false; } const int N = 2e6 + 7; int n, m, t; int dp[N]; vector<int> adj[N]; void dfs(int u, int p) { int F = 0, S = 0; for (int v: adj[u]) if (v != p) { dfs(v, u); if (F < dp[v]) { S = F; F = dp[v]; } else { maximize(S, dp[v]); } } dp[u] = (int) adj[u].size() + S - 1; } signed main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> t >> m; for (int i = 1; i < n; i ++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } dfs(t, m); cout << dp[t]; 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...