Submission #571471

#TimeUsernameProblemLanguageResultExecution timeMemory
571471piOOEMousetrap (CEOI17_mousetrap)C++17
25 / 100
679 ms73376 KiB
#include <bits/stdc++.h> using namespace std; #define sz(x) ((int)size(x)) #define all(x) begin(x), end(x) #define trace(x) cout << #x << ": " << (x) << endl; typedef long long ll; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; } template<typename T> bool ckmn(T &x, T y) { if (x > y) { x = y; return true; } return false; } template<typename T> bool ckmx(T &x, T y) { if (x < y) { x = y; return true; } return false; } const int N = 1000001, infI = 1e9 + 7; const ll infL = 3e18; int n, t, m; vector<int> g[N]; int dp[N]; void dfs(int v, int p) { int mx1 = 0, mx2 = 0, cnt = 0; for (int to : g[v]) { if (to != p) { ++cnt; dfs(to, v); if (mx1 < dp[to]) { mx2 = mx1; mx1 = dp[to]; } else if (mx2 < dp[to]){ mx2 = dp[to]; } } } dp[v] = 1 + mx2 + (cnt - 1); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> t >> m; --t, --m; for (int i = 1; i < n; ++i) { int a, b; cin >> a >> b; --a, --b; g[a].push_back(b); g[b].push_back(a); } dfs(t, -1); cout << dp[m]; 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...