QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#368149#3100. Meetings 20x3b8000010 2ms12600kbC++142.8kb2024-03-26 21:12:512024-03-26 21:12:51

Judging History

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

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

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], 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;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 4
Accepted
time: 2ms
memory: 11988kb

input:

1

output:

1

result:

ok single line: '1'

Test #2:

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

input:

2
2 1

output:

1
2

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 11884kb

input:

3
1 3
3 2

output:

1
3
1

result:

ok 3 lines

Test #4:

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

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: 0
Accepted
time: 1ms
memory: 12600kb

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

result:

ok 14 lines

Test #6:

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

input:

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

output:

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

result:

ok 14 lines

Test #7:

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

input:

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

output:

1
7
1
5
1
3
1
2
1
2
1
1
1
1

result:

ok 14 lines

Test #8:

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

input:

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

output:

1
8
1
6
1
4
1
4
1
3
1
2
1
1
1

result:

ok 15 lines

Test #9:

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

input:

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

output:

1
8
1
6
1
4
1
4
1
2
1
2
1
2
1
2

result:

ok 16 lines

Test #10:

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

input:

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

output:

1
10
1
8
1
6
1
4
1
4
1
4
1
2
1
2

result:

ok 16 lines

Test #11:

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

input:

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

output:

1
7
1
5
1
5
1
2
1
2
1
2
1
2
1
1

result:

wrong answer 8th lines differ - expected: '3', found: '2'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%