Submission #1026230

# Submission time Handle Problem Language Result Execution time Memory
1026230 2024-07-17T18:02:23 Z AdamGS Meetings 2 (JOI21_meetings2) C++17
100 / 100
1072 ms 30332 KB
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7, INF=1e9+7;
vector<int>V[LIM], spojna;
int usun[LIM], ile[LIM], odl[LIM], ans[2*LIM], n;
int tr[4*LIM], N;
int cnt(int l, int r) {
  l+=N; r+=N;
  int ma=max(tr[l], tr[r]);
  while(l/2!=r/2) {
    if(l%2==0) ma=max(ma, tr[l+1]);
    if(r%2==1) ma=max(ma, tr[r-1]);
    l/=2; r/=2;
  }
  return ma;
}
void upd(int v, int x) {
  v+=N;
  while(v) {
    tr[v]=max(tr[v], x);
    v/=2;
  }
}
void DFS(int x, int o) {
  spojna.pb(x);
  ile[x]=1;
  for(auto i : V[x]) if(!usun[i] && i!=o) {
    odl[i]=odl[x]+1;
    DFS(i, x);
    ile[x]+=ile[i];
  }
}
void DFS2(int x, int o, int p) {
  ans[2*ile[x]]=max(ans[2*ile[x]], cnt(ile[x], N-1)+odl[x]+1);
  ans[2*min(p, ile[x])]=max(ans[2*min(p, ile[x])], odl[x]+1);
  for(auto i : V[x]) if(!usun[i] && i!=o) DFS2(i, x, p);
}
void DFS3(int x, int o) {
  upd(ile[x], odl[x]);
  for(auto i : V[x]) if(!usun[i] && i!=o) DFS3(i, x);
}
int cent(int x) {
  spojna.clear();
  DFS(x, x);
  for(auto i : spojna) {
    int ma=(int)spojna.size()-ile[i];
    for(auto j : V[i]) if(!usun[j] && ile[j]<ile[i]) ma=max(ma, ile[j]);
    if(2*ma<=spojna.size()) x=i;
  }
  return x;
}
void cd(int x) {
  x=cent(x);
  spojna.clear();
  odl[x]=0;
  DFS(x, x);
  usun[x]=1;
  N=1;
  while(N<=spojna.size()) N*=2;
  rep(i, 2*N) tr[i]=-INF;
  for(auto i : V[x]) if(!usun[i]) {
    DFS2(i, x, (int)spojna.size()-ile[i]);
    DFS3(i, x);
  }
  rep(i, 2*N) tr[i]=-INF;
  reverse(all(V[x]));
  for(auto i : V[x]) if(!usun[i]) {
    DFS2(i, x, (int)spojna.size()-ile[i]);
    DFS3(i, x);
  }
  reverse(all(V[x]));
  for(auto i : V[x]) if(!usun[i]) cd(i);
}
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin >> n;
  rep(i, n-1) {
    int a, b;
    cin >> a >> b; --a; --b;
    V[a].pb(b);
    V[b].pb(a);
  }
  ans[2*LIM-1]=1;
  cd(0);
  for(int i=2*LIM-2; i; --i) ans[i]=max(ans[i+1], ans[i]);
  rep(i, n) if(i%2==0) ans[i+1]=1;
  rep(i, n) cout << ans[i+1] << '\n';
}

Compilation message

meetings2.cpp: In function 'int cent(int)':
meetings2.cpp:55:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     if(2*ma<=spojna.size()) x=i;
      |        ~~~~^~~~~~~~~~~~~~~
meetings2.cpp: In function 'void cd(int)':
meetings2.cpp:66:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   while(N<=spojna.size()) N*=2;
      |         ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6492 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
3 Correct 5 ms 6676 KB Output is correct
4 Correct 4 ms 6520 KB Output is correct
5 Correct 4 ms 6492 KB Output is correct
6 Correct 4 ms 6492 KB Output is correct
7 Correct 4 ms 6488 KB Output is correct
8 Correct 4 ms 6492 KB Output is correct
9 Correct 4 ms 6492 KB Output is correct
10 Correct 4 ms 6492 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 4 ms 6568 KB Output is correct
13 Correct 4 ms 6492 KB Output is correct
14 Correct 4 ms 6492 KB Output is correct
15 Correct 4 ms 6492 KB Output is correct
16 Correct 4 ms 6696 KB Output is correct
17 Correct 4 ms 6736 KB Output is correct
18 Correct 4 ms 6488 KB Output is correct
19 Correct 4 ms 6492 KB Output is correct
20 Correct 4 ms 6748 KB Output is correct
21 Correct 4 ms 6584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6492 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
3 Correct 5 ms 6676 KB Output is correct
4 Correct 4 ms 6520 KB Output is correct
5 Correct 4 ms 6492 KB Output is correct
6 Correct 4 ms 6492 KB Output is correct
7 Correct 4 ms 6488 KB Output is correct
8 Correct 4 ms 6492 KB Output is correct
9 Correct 4 ms 6492 KB Output is correct
10 Correct 4 ms 6492 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 4 ms 6568 KB Output is correct
13 Correct 4 ms 6492 KB Output is correct
14 Correct 4 ms 6492 KB Output is correct
15 Correct 4 ms 6492 KB Output is correct
16 Correct 4 ms 6696 KB Output is correct
17 Correct 4 ms 6736 KB Output is correct
18 Correct 4 ms 6488 KB Output is correct
19 Correct 4 ms 6492 KB Output is correct
20 Correct 4 ms 6748 KB Output is correct
21 Correct 4 ms 6584 KB Output is correct
22 Correct 8 ms 6748 KB Output is correct
23 Correct 8 ms 7012 KB Output is correct
24 Correct 9 ms 7004 KB Output is correct
25 Correct 8 ms 7004 KB Output is correct
26 Correct 8 ms 7004 KB Output is correct
27 Correct 8 ms 7004 KB Output is correct
28 Correct 8 ms 7004 KB Output is correct
29 Correct 8 ms 6988 KB Output is correct
30 Correct 8 ms 7004 KB Output is correct
31 Correct 8 ms 6856 KB Output is correct
32 Correct 10 ms 7004 KB Output is correct
33 Correct 12 ms 7216 KB Output is correct
34 Correct 6 ms 7004 KB Output is correct
35 Correct 5 ms 6964 KB Output is correct
36 Correct 8 ms 7004 KB Output is correct
37 Correct 6 ms 7004 KB Output is correct
38 Correct 7 ms 7108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6492 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
3 Correct 5 ms 6676 KB Output is correct
4 Correct 4 ms 6520 KB Output is correct
5 Correct 4 ms 6492 KB Output is correct
6 Correct 4 ms 6492 KB Output is correct
7 Correct 4 ms 6488 KB Output is correct
8 Correct 4 ms 6492 KB Output is correct
9 Correct 4 ms 6492 KB Output is correct
10 Correct 4 ms 6492 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 4 ms 6568 KB Output is correct
13 Correct 4 ms 6492 KB Output is correct
14 Correct 4 ms 6492 KB Output is correct
15 Correct 4 ms 6492 KB Output is correct
16 Correct 4 ms 6696 KB Output is correct
17 Correct 4 ms 6736 KB Output is correct
18 Correct 4 ms 6488 KB Output is correct
19 Correct 4 ms 6492 KB Output is correct
20 Correct 4 ms 6748 KB Output is correct
21 Correct 4 ms 6584 KB Output is correct
22 Correct 8 ms 6748 KB Output is correct
23 Correct 8 ms 7012 KB Output is correct
24 Correct 9 ms 7004 KB Output is correct
25 Correct 8 ms 7004 KB Output is correct
26 Correct 8 ms 7004 KB Output is correct
27 Correct 8 ms 7004 KB Output is correct
28 Correct 8 ms 7004 KB Output is correct
29 Correct 8 ms 6988 KB Output is correct
30 Correct 8 ms 7004 KB Output is correct
31 Correct 8 ms 6856 KB Output is correct
32 Correct 10 ms 7004 KB Output is correct
33 Correct 12 ms 7216 KB Output is correct
34 Correct 6 ms 7004 KB Output is correct
35 Correct 5 ms 6964 KB Output is correct
36 Correct 8 ms 7004 KB Output is correct
37 Correct 6 ms 7004 KB Output is correct
38 Correct 7 ms 7108 KB Output is correct
39 Correct 567 ms 21196 KB Output is correct
40 Correct 541 ms 20928 KB Output is correct
41 Correct 516 ms 21200 KB Output is correct
42 Correct 535 ms 21456 KB Output is correct
43 Correct 603 ms 21460 KB Output is correct
44 Correct 530 ms 21452 KB Output is correct
45 Correct 1072 ms 26268 KB Output is correct
46 Correct 979 ms 30332 KB Output is correct
47 Correct 137 ms 21580 KB Output is correct
48 Correct 119 ms 21832 KB Output is correct
49 Correct 589 ms 21968 KB Output is correct
50 Correct 186 ms 21864 KB Output is correct
51 Correct 539 ms 29256 KB Output is correct