Submission #546414

# Submission time Handle Problem Language Result Execution time Memory
546414 2022-04-07T13:27:43 Z cadmiumsky Meetings 2 (JOI21_meetings2) C++14
20 / 100
958 ms 1064 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int nmax = 4e3 + 5;
 
int n;
vector<int> g[nmax];
int pin[nmax], pout[nmax], inp;
int area[nmax], depth[nmax];
int p[nmax][16];
void init(int node, int f) {
  p[node][0] = f;
  depth[node] = depth[f] + 1;
  area[node] ++;
  pin[node] = inp++;
  for(int i = 1; i < 16; i++)
    p[node][i] = p[p[node][i - 1]][i - 1];
  //cout << node << '\n';
  //for(int i = 0; i < 16; i++)
    //cout << p[node][i] << ' ';
  //cout << '\n';
  for(auto x : g[node]) {
    if(x == f)
      continue;
    init(x, node);
    area[node] += area[x];
  }
  pout[node] = inp - 1;
  return;
}
bool isanc(int f, int node) {
  return pin[f] <= pin[node] && pout[node] <= pout[f];
}
int rez[nmax];
int blca(int x, int y) {
  int temp = x;
  for(int i = 15; i >= 0; i--) {
    if(!isanc(p[temp][i], y))
      temp = p[temp][i];
  }
  return temp;
}
void upd(int x, int y) {
  if(isanc(y, x)) 
    swap(x, y);
  if(isanc(x, y)) {
    int k = blca(y, x);
    //cout << x << ' ' << y << ' ' << k << ' ' << isanc(k, y) << '\n';
    //cout << n - area[k] <<
    int u = min(n - area[k], area[y]);
    rez[u * 2] = max(rez[u * 2], depth[y] - depth[x] + 1);
    return;
  }
  else {
    int u = min(area[x], area[y]);
    int lca = blca(x, y);
    lca = p[lca][0];
    rez[u * 2] = max(rez[u * 2], depth[x] + depth[y] - 2 * depth[lca] + 1);
  }
  return;
}
 
int main() {
  cin >> n;
  for(int i = 1, x, y; i < n; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  init(1, 1);
  for(int i = 1; i <= n; i++) {
    for(int j = i + 1; j <= n; j++)
      upd(i, j);
  }
  for(int i = n; i > 0; i--) {
    if(i % 2 == 0)
      rez[i] = max({1, rez[i + 2], rez[i]});
    else
      rez[i] = 1;
  }
  for(int i = 1; i <= n; i++) {
    cout << rez[i] << '\n'; 
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 400 KB Output is correct
16 Correct 1 ms 404 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 400 KB Output is correct
16 Correct 1 ms 404 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 625 ms 864 KB Output is correct
23 Correct 606 ms 868 KB Output is correct
24 Correct 611 ms 868 KB Output is correct
25 Correct 594 ms 872 KB Output is correct
26 Correct 603 ms 860 KB Output is correct
27 Correct 619 ms 864 KB Output is correct
28 Correct 595 ms 992 KB Output is correct
29 Correct 625 ms 864 KB Output is correct
30 Correct 599 ms 876 KB Output is correct
31 Correct 622 ms 992 KB Output is correct
32 Correct 802 ms 980 KB Output is correct
33 Correct 958 ms 1064 KB Output is correct
34 Correct 593 ms 868 KB Output is correct
35 Correct 605 ms 876 KB Output is correct
36 Correct 757 ms 904 KB Output is correct
37 Correct 616 ms 972 KB Output is correct
38 Correct 698 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 400 KB Output is correct
16 Correct 1 ms 404 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 625 ms 864 KB Output is correct
23 Correct 606 ms 868 KB Output is correct
24 Correct 611 ms 868 KB Output is correct
25 Correct 594 ms 872 KB Output is correct
26 Correct 603 ms 860 KB Output is correct
27 Correct 619 ms 864 KB Output is correct
28 Correct 595 ms 992 KB Output is correct
29 Correct 625 ms 864 KB Output is correct
30 Correct 599 ms 876 KB Output is correct
31 Correct 622 ms 992 KB Output is correct
32 Correct 802 ms 980 KB Output is correct
33 Correct 958 ms 1064 KB Output is correct
34 Correct 593 ms 868 KB Output is correct
35 Correct 605 ms 876 KB Output is correct
36 Correct 757 ms 904 KB Output is correct
37 Correct 616 ms 972 KB Output is correct
38 Correct 698 ms 956 KB Output is correct
39 Runtime error 1 ms 596 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -