QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368147#3100. Meetings 20x3b8000010 2ms12320kbC++142.8kb2024-03-26 21:12:032024-03-26 21:12:04

Judging History

你现在查看的是最新测评结果

  • [2024-03-26 21:12:04]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:12320kb
  • [2024-03-26 21:12:03]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <vector>

int n;
std::vector<int> E[200007];
int fa[200007], sz[200007], maxsz[200007], dep[200007];

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);
    }
  }
  for (int t = 0; t < 2; ++t) {
    for (auto i : sons) {
      for (int j : i) {
        int d = query(n + 1 - sz[j]);
        if (d) {
          ans[sz[j]] = std::max(ans[sz[j]], 1 + dep[j] + d);
        }
      }
      for (int j : i) {
        modify(n + 1 - sz[j], dep[j]);
      }
    }
    for (auto i : sons) {
      for (int j : i) {
        modify0(n + 1 - sz[j]);
      }
    }
    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);
  }
  Divide_Conquer(t);
  std::vector<int> s;
  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], 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: 2ms
memory: 12320kb

input:

1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 2ms
memory: 10776kb

input:

2
2 1

output:

1
2

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 2ms
memory: 12316kb

input:

3
1 3
3 2

output:

1
3
1

result:

ok 3 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 11236kb

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
2
1
2
1
2

result:

ok 14 lines

Test #5:

score: -4
Wrong Answer
time: 2ms
memory: 11140kb

input:

14
10 14
3 10
14 13
1 3
3 5
3 11
12 14
14 6
11 8
2 3
7 8
9 7
1 4

output:

1
8
1
6
1
5
1
4
1
2
1
0
1
0

result:

wrong answer 12th lines differ - expected: '1', found: '0'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%