Submission #122822

#TimeUsernameProblemLanguageResultExecution timeMemory
122822popovicirobertTriumphal arch (POI13_luk)C++14
100 / 100
1111 ms28972 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long // 217 // 44 /* const int MOD = ; inline void mod(int &x) { if(x >= MOD) x -= MOD; } inline void add(int &x, int y) { x += y; mod(x); } inline void sub(int &x, int y) { x += MOD - y; mod(x); } inline void mul(int &x, int y) { x = (1LL * x * y) % MOD; } */ using namespace std; vector < vector <int> > g; vector <int> dp; void dfs(int nod, int par, int delta) { dp[nod] = 0; for(auto it : g[nod]) { if(it != par) { dfs(it, nod, delta); dp[nod] += dp[it] + 1; } } dp[nod] = max(dp[nod] - delta, 0); } int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i, n; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; g.resize(n + 1), dp.resize(n + 1); for(i = 1; i < n; i++) { int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } int res = -1; for(int step = 1 << 18; step; step >>= 1) { dfs(1, 0, res + step); if(dp[1] > 0) { res += step; } } cout << res + 1; //cin.close(); //cout.close(); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...