Submission #559146

#TimeUsernameProblemLanguageResultExecution timeMemory
559146fatemetmhrMousetrap (CEOI17_mousetrap)C++17
25 / 100
676 ms73392 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) x.begin(), x.end() #define fi first #define se second #define pb push_back const int maxn5 = 1e6 + 10; int tale, mo, dp[maxn5]; vector <int> adj[maxn5]; inline void dfs(int v, int par){ int mx = 0, smx = 0; for(auto u : adj[v]) if(u != par && u != tale){ dfs(u, v); if(dp[u] >= mx){ smx = mx; mx = dp[u]; } else smx = max(smx, dp[u]); } dp[v] = smx + adj[v].size() - 1; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, a, b; cin >> n >> a >> b; a--; b--; mo = b; tale = a; for(int i = 0; i < n - 1; i++){ int a, b; cin >> a >> b; a--; b--; adj[a].pb(b); adj[b].pb(a); } assert(a != b); if(a == b) return cout << 0 << endl, 0; dfs(mo, -1); cout << dp[mo] << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...