Submission #852962

#TimeUsernameProblemLanguageResultExecution timeMemory
852962danikoynovMeetings 2 (JOI21_meetings2)C++14
0 / 100
4 ms17756 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_sub[maxn]; set < pair < int, int > > act[maxn]; void dfs(int v, int p) { for (int u : adj[v]) { if (u == p) continue; dfs(u, v); for (pair < int, int > cur : act[v]) { set < pair < int, int > > :: iterator it = act[u].lower_bound(cur); if (it != act[u].end()) { int id = cur.first * 2; max_chain[id] = max(max_chain[id], cur.second + it -> second - 2 * depth[v]); } } for (pair < int, int > cur : act[u]) { set < pair < int, int > > :: iterator it = act[v].lower_bound(cur); if (it != act[v].end()) { int id = cur.first * 2; ///cout << "here " << v << " " << id << " " << cur.first << " " << cur.second << endl; max_chain[id] = max(max_chain[id], cur.second + it -> second - 2 * depth[v]); } int vir_sub = n - sub[u]; int id = 2 * min(vir_sub, cur.first); max_chain[id] = max(max_chain[id], cur.second - depth[v]); } for (pair < int, int > cur1 : act[v]) for (pair < int, int > cur2 : act[u]) { int id = 2 * min(cur1.first, cur2.first); max_chain[id] = max(max_chain[id], cur1.second + cur2.second - 2 * depth[v]); } for (pair < int, int > cur : act[u]) { set < pair < int, int > > :: iterator it = act[v].lower_bound(cur); if (it != act[v].end() && it -> second >= cur.second) continue; act[v].insert(cur); while(true) { it = act[v].find(cur); if (it == act[v].begin()) break; it = prev(it); if (it -> second <= cur.second) act[v].erase(it); else break; } } } pair < int, int > cur = {sub[v], depth[v]}; set < pair < int, int > > :: iterator it = act[v].lower_bound(cur); if (it != act[v].end() && it -> second >= cur.second) return; act[v].insert(cur); while(true) { it = act[v].find(cur); if (it == act[v].begin()) break; it = prev(it); if (it -> second <= cur.second) act[v].erase(it); else break; } /**cout << "step " << v << endl; for (pair < int, int > cur : act[v]) cout << cur.first << " : " << cur.second << endl;*/ } 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 = 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...