답안 #986252

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986252 2024-05-20T07:01:48 Z cig32 Meetings 2 (JOI21_meetings2) C++17
20 / 100
4000 ms 21952 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { 
  return bm(b, MOD-2);
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
static void run_with_stack_size(void (*func)(void), size_t stsize) {
  char *stack, *send;
  stack = (char *)malloc(stsize);
  send = stack + stsize - 16;
  send = (char *)((uintptr_t)send / 16 * 16);
  asm volatile(
    "mov %%rsp, (%0)\n"
    "mov %0, %%rsp\n"
    :
    : "r"(send));
  func();
  asm volatile("mov (%0), %%rsp\n" : : "r"(send));
  free(stack);
}
vector<int> adj[MAXN];
int ans[MAXN], n, sz[MAXN];
void dfs(int node, int prv) {
  sz[node] = 1;
  for(int x: adj[node]) {
    if(x != prv) {
      dfs(x, node);
      sz[node] += sz[x];
    }
  }
}
int check(int node, int prv, int tar, int depth) {
  int ans = 0;
  if(sz[node] >= tar) ans = depth;
  for(int x: adj[node]) {
    if(x != prv) {
      ans = max(ans, check(x, node, tar, depth + 1));
    }
  }
  return ans;
}
void solve(int tc) {
  cin >> n;
  for(int i=1; i<n; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for(int i=1; i<=n; i++) {
    dfs(i, -1);
    for(int x: adj[i]) {
      int len = n - sz[x];
      int ret = check(x, i, len, 1);
      ans[len * 2] = max(ans[len * 2], ret + 1);
    }
  }
  ans[n] = max(ans[n], 1ll);
  for(int i=n-1; i>=1; i--) ans[i] = max(ans[i], ans[i+1]);
  for(int i=1; i<=n; i++) {
    cout << (i % 2 == 1 ? 1 : ans[i]) << "\n";
  }
}
void uwu() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
int32_t main() {
  #ifdef ONLINE_JUDGE
  uwu();
  #endif
  #ifndef ONLINE_JUDGE
  run_with_stack_size(uwu, 1024 * 1024 * 1024); // run with a 1 GiB stack
  #endif
}
/*
g++ B.cpp -std=c++17 -O2 -o B
./B < input.txt
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 2 ms 9820 KB Output is correct
3 Correct 2 ms 9904 KB Output is correct
4 Correct 2 ms 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 2 ms 9820 KB Output is correct
7 Correct 2 ms 9820 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
9 Correct 2 ms 9816 KB Output is correct
10 Correct 3 ms 11868 KB Output is correct
11 Correct 2 ms 9816 KB Output is correct
12 Correct 2 ms 9820 KB Output is correct
13 Correct 3 ms 9820 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 2 ms 9820 KB Output is correct
17 Correct 3 ms 9820 KB Output is correct
18 Correct 2 ms 9820 KB Output is correct
19 Correct 2 ms 9816 KB Output is correct
20 Correct 2 ms 9820 KB Output is correct
21 Correct 2 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 2 ms 9820 KB Output is correct
3 Correct 2 ms 9904 KB Output is correct
4 Correct 2 ms 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 2 ms 9820 KB Output is correct
7 Correct 2 ms 9820 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
9 Correct 2 ms 9816 KB Output is correct
10 Correct 3 ms 11868 KB Output is correct
11 Correct 2 ms 9816 KB Output is correct
12 Correct 2 ms 9820 KB Output is correct
13 Correct 3 ms 9820 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 2 ms 9820 KB Output is correct
17 Correct 3 ms 9820 KB Output is correct
18 Correct 2 ms 9820 KB Output is correct
19 Correct 2 ms 9816 KB Output is correct
20 Correct 2 ms 9820 KB Output is correct
21 Correct 2 ms 9820 KB Output is correct
22 Correct 391 ms 10076 KB Output is correct
23 Correct 354 ms 10204 KB Output is correct
24 Correct 324 ms 10200 KB Output is correct
25 Correct 348 ms 10072 KB Output is correct
26 Correct 368 ms 10200 KB Output is correct
27 Correct 361 ms 10076 KB Output is correct
28 Correct 368 ms 10076 KB Output is correct
29 Correct 366 ms 10072 KB Output is correct
30 Correct 374 ms 10196 KB Output is correct
31 Correct 354 ms 10208 KB Output is correct
32 Correct 330 ms 10580 KB Output is correct
33 Correct 303 ms 12416 KB Output is correct
34 Correct 236 ms 10076 KB Output is correct
35 Correct 133 ms 10076 KB Output is correct
36 Correct 211 ms 10224 KB Output is correct
37 Correct 135 ms 10208 KB Output is correct
38 Correct 212 ms 10356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 2 ms 9820 KB Output is correct
3 Correct 2 ms 9904 KB Output is correct
4 Correct 2 ms 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 2 ms 9820 KB Output is correct
7 Correct 2 ms 9820 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
9 Correct 2 ms 9816 KB Output is correct
10 Correct 3 ms 11868 KB Output is correct
11 Correct 2 ms 9816 KB Output is correct
12 Correct 2 ms 9820 KB Output is correct
13 Correct 3 ms 9820 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 2 ms 9820 KB Output is correct
17 Correct 3 ms 9820 KB Output is correct
18 Correct 2 ms 9820 KB Output is correct
19 Correct 2 ms 9816 KB Output is correct
20 Correct 2 ms 9820 KB Output is correct
21 Correct 2 ms 9820 KB Output is correct
22 Correct 391 ms 10076 KB Output is correct
23 Correct 354 ms 10204 KB Output is correct
24 Correct 324 ms 10200 KB Output is correct
25 Correct 348 ms 10072 KB Output is correct
26 Correct 368 ms 10200 KB Output is correct
27 Correct 361 ms 10076 KB Output is correct
28 Correct 368 ms 10076 KB Output is correct
29 Correct 366 ms 10072 KB Output is correct
30 Correct 374 ms 10196 KB Output is correct
31 Correct 354 ms 10208 KB Output is correct
32 Correct 330 ms 10580 KB Output is correct
33 Correct 303 ms 12416 KB Output is correct
34 Correct 236 ms 10076 KB Output is correct
35 Correct 133 ms 10076 KB Output is correct
36 Correct 211 ms 10224 KB Output is correct
37 Correct 135 ms 10208 KB Output is correct
38 Correct 212 ms 10356 KB Output is correct
39 Execution timed out 4059 ms 21952 KB Time limit exceeded
40 Halted 0 ms 0 KB -