답안 #869071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869071 2023-11-03T05:17:23 Z azberjibiou Meetings 2 (JOI21_meetings2) C++17
0 / 100
10 ms 48036 KB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
using namespace std;
const int mxN=200030;
const int mxM=500004;
const int MOD=998244353;
const ll INF=8e18;
typedef struct node{
    int p, m, pm, mp, pmp;
}node;
node mrg(node a, node b){
    node c;
    c.p=max(a.p, b.p);
    c.m=max(a.m, b.m);
    c.pm=max(a.p+b.m, max(a.pm, b.pm));
    c.mp=max(a.m+b.p, max(a.mp, b.mp));
    c.pmp=max(a.pm+b.p, max(a.p+b.mp, max(a.pmp, b.pmp)));
    return c;
}
node seg[8*mxN];
void upd(int idx, int s, int e, int pos, int val){
    if(s==e){
        seg[idx].p=val;
        seg[idx].m=-val;
        seg[idx].pm=seg[idx].mp=0;
        seg[idx].pmp=val;
        return;
    }
    int mid=(s+e)/2;
    if(pos<=mid)    upd(2*idx, s, mid, pos, val);
    else    upd(2*idx+1, mid+1, e, pos, val);
    seg[idx]=mrg(seg[2*idx], seg[2*idx+1]);
}
int N;
vector <int> v[mxN];
int sub[mxN], dep[mxN];
vector <int> in[mxN];
int ei;
vector <int> ct[mxN];
int ans[mxN];
void input(){
    cin >> N;
    for(int i=1;i<N;i++){
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
}
void dfs1(int now, int pre){
    sub[now]=1;
    in[now].push_back(++ei);
    for(int nxt : v[now]) if(nxt!=pre) {
        dep[nxt]=dep[now]+1;
        dfs1(nxt, now);
        sub[now]+=sub[nxt];
        in[now].push_back(++ei);
    }
}
void find_cent(){
    dfs1(1, -1);
    int now=1;
    while(true){
        bool esc=true;
        for(int nxt : v[now]){
            if(sub[nxt]<sub[now] && sub[nxt]>=(N+1)/2){
                now=nxt;
                esc=false;
                break;
            }
        }
        if(esc) break;
    }
    ei=0;
    dep[now]=0;
    for(int i=1;i<=N;i++)   in[i].clear();
    dfs1(now, -1);
    for(int i=1;i<=N;i++)   ct[sub[i]].push_back(i);
    for(int i=0;i<8*mxN;i++)    seg[i].p=seg[i].m=seg[i].pm=seg[i].mp=seg[i].pmp=-1e8;
    for(int x : in[now])    upd(1, 1, 2*N, x, dep[now]);
    //for(int i=1;i<=N;i++)   printf("dep[%d]=%d, sub[%d], in[%d]=%d\n", i, dep[i], i, sub[i], i, in[i]);
}
void solv(){
    for(int i=N;i>=1;i--){
        if(i%2){
            ans[i]=1;
            continue;
        }
        //printf("i=%d\n", i);
        for(int x : ct[i/2]) for(int y : in[x]) upd(1, 1, 2*N, y, dep[x]);
        //printf("\n");
        ans[i]=seg[1].pmp+1;
    }
}
int main()
{
    gibon
    input();
    find_cent();
    solv();
    for(int i=1;i<=N;i++)   cout << ans[i] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 47964 KB Output is correct
2 Correct 9 ms 47864 KB Output is correct
3 Correct 9 ms 47964 KB Output is correct
4 Correct 9 ms 47964 KB Output is correct
5 Correct 9 ms 47816 KB Output is correct
6 Correct 9 ms 47964 KB Output is correct
7 Correct 10 ms 47964 KB Output is correct
8 Correct 9 ms 47964 KB Output is correct
9 Correct 9 ms 47964 KB Output is correct
10 Correct 10 ms 47964 KB Output is correct
11 Correct 9 ms 47964 KB Output is correct
12 Correct 9 ms 47852 KB Output is correct
13 Correct 10 ms 47964 KB Output is correct
14 Correct 9 ms 47964 KB Output is correct
15 Correct 9 ms 47896 KB Output is correct
16 Correct 9 ms 47964 KB Output is correct
17 Correct 9 ms 47964 KB Output is correct
18 Correct 9 ms 48036 KB Output is correct
19 Incorrect 9 ms 48036 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 47964 KB Output is correct
2 Correct 9 ms 47864 KB Output is correct
3 Correct 9 ms 47964 KB Output is correct
4 Correct 9 ms 47964 KB Output is correct
5 Correct 9 ms 47816 KB Output is correct
6 Correct 9 ms 47964 KB Output is correct
7 Correct 10 ms 47964 KB Output is correct
8 Correct 9 ms 47964 KB Output is correct
9 Correct 9 ms 47964 KB Output is correct
10 Correct 10 ms 47964 KB Output is correct
11 Correct 9 ms 47964 KB Output is correct
12 Correct 9 ms 47852 KB Output is correct
13 Correct 10 ms 47964 KB Output is correct
14 Correct 9 ms 47964 KB Output is correct
15 Correct 9 ms 47896 KB Output is correct
16 Correct 9 ms 47964 KB Output is correct
17 Correct 9 ms 47964 KB Output is correct
18 Correct 9 ms 48036 KB Output is correct
19 Incorrect 9 ms 48036 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 47964 KB Output is correct
2 Correct 9 ms 47864 KB Output is correct
3 Correct 9 ms 47964 KB Output is correct
4 Correct 9 ms 47964 KB Output is correct
5 Correct 9 ms 47816 KB Output is correct
6 Correct 9 ms 47964 KB Output is correct
7 Correct 10 ms 47964 KB Output is correct
8 Correct 9 ms 47964 KB Output is correct
9 Correct 9 ms 47964 KB Output is correct
10 Correct 10 ms 47964 KB Output is correct
11 Correct 9 ms 47964 KB Output is correct
12 Correct 9 ms 47852 KB Output is correct
13 Correct 10 ms 47964 KB Output is correct
14 Correct 9 ms 47964 KB Output is correct
15 Correct 9 ms 47896 KB Output is correct
16 Correct 9 ms 47964 KB Output is correct
17 Correct 9 ms 47964 KB Output is correct
18 Correct 9 ms 48036 KB Output is correct
19 Incorrect 9 ms 48036 KB Output isn't correct
20 Halted 0 ms 0 KB -