QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#368286 | #3100. Meetings 2 | 0x3b800001 | 0 | 3ms | 12820kb | C++14 | 3.2kb | 2024-03-26 22:58:48 | 2024-03-26 22:58:49 |
Judging History
answer
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <vector>
#include <map>
int n;
std::vector<int> E[200007];
int fa[200007], sz[200007], maxsz[200007], dep[200007];
std::map<std::pair<int, int>, int> Sz;
void dfs(int u, std::unordered_set<int>& vertex, std::vector<int>& vs) {
vs.push_back(u), sz[u] = 1, maxsz[u] = 0;
for (int v : E[u]) {
if (v != fa[u] && vertex.find(v) != vertex.end()) {
fa[v] = u;
dep[v] = dep[u] + 1;
dfs(v, vertex, vs);
sz[u] += sz[v];
maxsz[u] = std::max(maxsz[u], sz[v]);
}
}
maxsz[u] = std::max(maxsz[u], int(vertex.size()) - sz[u]);
}
int findG(std::unordered_set<int> vertex) {
std::vector<int> tmp;
int t = *vertex.begin();
dfs(t, vertex, tmp);
for (int i : vertex) {
if (maxsz[i] < maxsz[t]) {
t = i;
}
}
return t;
}
int lowbit(int x) { return x & (-x); }
int bit[200007];
int query(int x) {
if (x == 0) {
return 0;
}
return std::max(bit[x], query(x - lowbit(x)));
}
void modify(int x, int d) {
if (x > n) {
return;
}
bit[x] = std::max(bit[x], d);
modify(x + lowbit(x), d);
}
void modify0(int x) {
if (x > n) {
return;
}
bit[x] = 0;
modify0(x + lowbit(x));
}
int ans[200007];
void Divide_Conquer(std::unordered_set<int> vertex) {
int root = findG(vertex);
std::vector<std::vector<int>> sons;
for (int i : E[root]) {
if (vertex.find(i) != vertex.end()) {
std::vector<int> st;
fa[i] = root, dep[i] = 1;
dfs(i, vertex, st);
sons.push_back(st);
}
}
int szr = n - vertex.size() + 1;
for (int t = 0; t < 2; ++t) {
for (auto i : sons) {
for (int j : i) {
int S = Sz[{fa[j], j}];
int d = query(n + 1 - S);
if (d) {
ans[S] = std::max(ans[S], 1 + dep[j] + d);
}
ans[std::min(S, szr)] = std::max(ans[std::min(S, szr)], dep[j] + 1);
}
for (int j : i) {
int S = Sz[{fa[j], j}];
modify(n + 1 - S, dep[j]);
}
}
for (auto i : sons) {
for (int j : i) {
int S = Sz[{fa[j], j}];
modify0(n + 1 - S);
}
}
std::reverse(sons.begin(), sons.end());
}
for (auto i : sons) {
Divide_Conquer(std::unordered_set<int>(i.begin(), i.end()));
}
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
std::cin >> n;
for (int i = 1; i < n; ++i) {
int u, v;
std::cin >> u >> v;
E[u].push_back(v), E[v].push_back(u);
}
std::unordered_set<int> t;
for (int i = 1; i <= n; ++i) {
t.insert(i);
}
std::vector<int> s;
fa[1] = 0, dfs(1, t, s);
for (int i = 2; i <= n; ++i) {
Sz[{fa[i], i}] = sz[i];
Sz[{i, fa[i]}] = n - sz[i];
}
Divide_Conquer(t);
fa[1] = 0, dfs(1, t, s);
int r = 0;
for (int i = 1; i <= n; ++i) {
r = std::max(r, std::min(sz[i], n - sz[i]));
}
ans[r] = std::max(ans[r], 2);
for (int i = n; i >= 1; --i) {
ans[i] = std::max(ans[i], 1);
ans[i] = std::max(ans[i], ans[i + 1]);
}
for (int i = 1; i <= n; ++i) {
if (i & 1) {
std::cout << "1\n";
} else {
std::cout << ans[i >> 1] << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 3ms
memory: 11304kb
input:
1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 12240kb
input:
2 2 1
output:
1 2
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 12820kb
input:
3 1 3 3 2
output:
1 3 1
result:
ok 3 lines
Test #4:
score: -4
Wrong Answer
time: 2ms
memory: 11932kb
input:
14 12 14 12 9 14 2 12 6 12 7 6 4 3 4 1 4 12 8 13 1 10 12 11 6 6 5
output:
1 7 1 5 1 3 1 3 1 3 1 3 1 3
result:
wrong answer 10th lines differ - expected: '2', found: '3'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%