Submission #1143134

#TimeUsernameProblemLanguageResultExecution timeMemory
1143134adimiclaus15Triumphal arch (POI13_luk)C++20
0 / 100
88 ms18504 KiB
#include <bits/stdc++.h> using namespace std; static const int MAXN = 300000; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; // Edge case: if n == 1, only the capital exists, so no crews needed. if (n == 1) { cout << 0 << "\n"; return 0; } vector<vector<int>> adj(n+1); for (int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } // BFS from node 1 to find distances vector<int> dist(n+1, -1); dist[1] = 0; queue<int>q; q.push(1); while (!q.empty()) { int u = q.front(); q.pop(); for (int v : adj[u]) { if (dist[v] == -1) { dist[v] = dist[u] + 1; q.push(v); } } } // We won't build an arch for the capital (dist=0). // Collect frequency of distances for dist >= 1 // Note: max distance in a tree can be up to (n-1) in a worst-case chain. // But we'll track only up to the maximum distance we actually see. int maxD = 0; for (int v = 2; v <= n; v++) { maxD = max(maxD, dist[v]); } vector<long long> freq(maxD+1, 0LL); for (int v = 2; v <= n; v++) { freq[dist[v]]++; } // Build partial sums: S(i) = freq[1] + freq[2] + ... + freq[i] // We only need i up to maxD long long runningSum = 0; long long answer = 0; // This will store the minimal K for (int i = 1; i <= maxD; i++) { runningSum += freq[i]; // S(i) // We need i * K >= S(i), i.e. K >= S(i)/i // So K >= ceil(S(i)/i) = (S(i) + i - 1) // i (integer division) long long needed = (runningSum + i - 1) / i; answer = max(answer, needed); } cout << answer << "\n"; 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...