Submission #852942

#TimeUsernameProblemLanguageResultExecution timeMemory
852942danikoynovMeetings 2 (JOI21_meetings2)C++14
20 / 100
4014 ms20800 KiB
/** ____ ____ ____ ____ ____ ____ ||l |||e |||i |||n |||a |||d || ||__|||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\|/__\| **/ #include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 2e5 + 10; int n; vector < int > adj[maxn]; int order[maxn], tin[maxn], tout[maxn]; int timer, depth[maxn], sub[maxn]; void euler(int v, int p) { order[++ timer] = v; tin[v] = timer; sub[v] = 1; for (int u : adj[v]) { if (u == p) continue; depth[u] = depth[v] + 1; euler(u, v); sub[v] += sub[u]; } tout[v] = timer; } vector < int > path; int max_chain[maxn], virtual_depth[maxn], virtual_sub[maxn]; int act[maxn]; void dfs(int v, int p) { for (int cur : path) { int id = 2 * min(virtual_sub[cur], sub[v]); max_chain[id] = max(max_chain[id], depth[v] - depth[cur]); ///cout << "here " << v << " " << cur << " " << virtual_sub[cur] << " " << sub[v] << endl; } path.push_back(v); virtual_depth[v] = -depth[v]; for (int u : adj[v]) { if (u == p) continue; virtual_sub[v] = n - sub[u]; dfs(u, v); } for (int i = 1; i < tin[v]; i ++) { if (act[order[i]]) { int id = 2 * min(sub[v], sub[order[i]]); //cout << v << " : " << order[i] << " " << depth[v] + virtual_depth[order[i]] << " " << id << endl; max_chain[id] = max(max_chain[id], depth[v] + virtual_depth[order[i]]); } } for (int i = tin[v]; i <= tout[v]; i ++) virtual_depth[order[i]] += 2; path.pop_back(); act[v] = 1; } void solve() { cin >> n; for (int i = 1; i < n; i ++) { int v, u; cin >> v >> u; adj[v].push_back(u); adj[u].push_back(v); } euler(1, 0); for (int i = 1; i <= n; i ++) { max_chain[i] = -1; } dfs(1, 0); for (int i = n; i > 0; i --) { max_chain[i] = max(max_chain[i], max_chain[i + 1]); } for (int i = 1; i <= n; i ++) { if (i % 2 == 1) cout << 1 << endl; else cout << max_chain[i] + 1 << endl; } } int main() { speed(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...