Submission #315249

#TimeUsernameProblemLanguageResultExecution timeMemory
315249shrek12357Triumphal arch (POI13_luk)C++14
100 / 100
1329 ms26088 KiB
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <map> #include <set> #include <climits> #include <cmath> #include <fstream> #include <queue> #include <stack> #include <bitset> using namespace std; #define ll long long //cin.tie(0);ios_base::sync_with_stdio(0); const int MAXN = 3 * 1e5 + 5; vector<int> adjList[MAXN]; int par[MAXN]; int n; int good; void dfs(int src) { for (auto i : adjList[src]) { if (i == par[src]) { continue; } par[i] = src; dfs(i); } } int check(int src, int mid) { int cur = 0; for (auto i : adjList[src]) { if (i == par[src]) { continue; } cur += check(i, mid) + 1; } cur -= mid; return max(0, cur); } int main() { cin >> n; par[0] = 0; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; adjList[a].push_back(b); adjList[b].push_back(a); } dfs(0); int lo = 0, hi = n; while (lo < hi) { int mid = (lo + hi) / 2; good = true; if (check(0, mid) == 0) { hi = mid; } else { lo = mid + 1; } } cout << lo << 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...
#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...