답안 #473182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
473182 2021-09-15T09:52:03 Z balbit Meetings 2 (JOI21_meetings2) C++14
20 / 100
407 ms 96836 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define y1 zck_is_king
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define REP(i,n) for (int i = 0; i<n; ++i)
#define RREP(i,n) for (int i = n-1; i>=0; --i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 2e5+5;

vector<int> g[maxn];

int sz[maxn], L[maxn], R[maxn], par[maxn], dep[maxn];
vector<int> children[maxn]; // including self
int IT = 0;

int lca[4005][4005];

void dfs1(int v, int p) {
    par[v] = p;
    sz[v] = 1;
    L[v] = R[v] = IT++;
    children[v].pb(v);
    for (int u : g[v]) {
        if (u != p) {
            dep[u] = dep[v] + 1;
            dfs1(u,v);
            sz[v] += sz[u];
            R[v] = R[u];
            for (int c : children[u]) {
                children[v].pb(c);
            }
        }
    }
}

bool isAnc(int a, int b) {
    // is a b's ancestor?
    return L[a] <= L[b] && R[a] >= R[b];
}

int n;

vector<int> quadratic() {
    dfs1(0, -1);


    REP(i,n) {
        for (int c : children[i]) {
            lca[i][c] = lca[c][i] = i;
        }
        for (int c : g[i]) {
            if (c != par[i]) {
                for (int c2 : g[i]) {
                    if (c2 > c && c2 != par[i]) {
                        for (int v1 : children[c]) for (int v2 : children[c2]) {
                            lca[v1][v2] = lca[v2][v1] = i;
                        }
                    }
                }
            }
        }
    }

    vector<int> dst(n); // max accommodation for this length
    auto go = [&](int a, int b, int s1, int s2) {
        bug(a,b,s1,s2);
        bug(dep[a] + dep[b] - dep[lca[a][b]]*2);
        MX(dst[dep[a] + dep[b] - dep[lca[a][b]]*2], min(s1, s2) * 2);
    };

    REP(a,n) for (int j : g[a]) if (j != par[a]) {
        for (int b : children[j]) {
            go(a,b,n-sz[j],sz[b]);
        }
    }

    REP(i,n) REP(j,i) {
        int a = i, b = j;
        if (dep[a] > dep[b]) swap(a,b);
        int s1, s2;
        if (isAnc(a,b)) {
            continue;
        }
        s1 = sz[a];
        s2 = sz[b];
        go(a,b,s1,s2);
//        bug(a,b,lca[a][b], s1, s2);
//        bug(dep[a] + dep[b] - dep[lca[a][b]] * 2);

    }
    for (int i = n-2; i>=0; --i) {
        MX(dst[i], dst[i+1]);
    }
    vector<int> ret(n+1);
    int j = 0;
    for (int i = n; i>=1; --i) {
        if (i % 2 == 1) ret[i] = 1;
        else{
            while (j+1 < n && dst[j+1] >= i) {
                ++j;
            }
            ret[i] = j+1;
            bug(i, ret[i]);
        }
    }
    return ret;
}

signed main(){
    IOS();
    cin>>n;
    REP(i,n-1) {
        int a,b; cin>>a>>b; --a; --b;
        g[a].pb(b); g[b].pb(a);
    }
    vector<int> yay = quadratic();
    REP1(i,n) {
        cout<<yay[i]<<endl;
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9676 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 6 ms 9676 KB Output is correct
5 Correct 6 ms 9768 KB Output is correct
6 Correct 6 ms 9728 KB Output is correct
7 Correct 6 ms 9800 KB Output is correct
8 Correct 6 ms 9732 KB Output is correct
9 Correct 6 ms 9804 KB Output is correct
10 Correct 7 ms 9732 KB Output is correct
11 Correct 7 ms 9804 KB Output is correct
12 Correct 6 ms 9804 KB Output is correct
13 Correct 6 ms 9804 KB Output is correct
14 Correct 6 ms 9732 KB Output is correct
15 Correct 6 ms 9804 KB Output is correct
16 Correct 6 ms 9804 KB Output is correct
17 Correct 6 ms 9724 KB Output is correct
18 Correct 6 ms 9716 KB Output is correct
19 Correct 6 ms 9724 KB Output is correct
20 Correct 7 ms 9728 KB Output is correct
21 Correct 6 ms 9804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9676 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 6 ms 9676 KB Output is correct
5 Correct 6 ms 9768 KB Output is correct
6 Correct 6 ms 9728 KB Output is correct
7 Correct 6 ms 9800 KB Output is correct
8 Correct 6 ms 9732 KB Output is correct
9 Correct 6 ms 9804 KB Output is correct
10 Correct 7 ms 9732 KB Output is correct
11 Correct 7 ms 9804 KB Output is correct
12 Correct 6 ms 9804 KB Output is correct
13 Correct 6 ms 9804 KB Output is correct
14 Correct 6 ms 9732 KB Output is correct
15 Correct 6 ms 9804 KB Output is correct
16 Correct 6 ms 9804 KB Output is correct
17 Correct 6 ms 9724 KB Output is correct
18 Correct 6 ms 9716 KB Output is correct
19 Correct 6 ms 9724 KB Output is correct
20 Correct 7 ms 9728 KB Output is correct
21 Correct 6 ms 9804 KB Output is correct
22 Correct 353 ms 72888 KB Output is correct
23 Correct 347 ms 72772 KB Output is correct
24 Correct 348 ms 72388 KB Output is correct
25 Correct 350 ms 72380 KB Output is correct
26 Correct 347 ms 72244 KB Output is correct
27 Correct 386 ms 73048 KB Output is correct
28 Correct 382 ms 73156 KB Output is correct
29 Correct 407 ms 73028 KB Output is correct
30 Correct 393 ms 73052 KB Output is correct
31 Correct 350 ms 73028 KB Output is correct
32 Correct 391 ms 86652 KB Output is correct
33 Correct 375 ms 96836 KB Output is correct
34 Correct 335 ms 72808 KB Output is correct
35 Correct 338 ms 72992 KB Output is correct
36 Correct 373 ms 74712 KB Output is correct
37 Correct 359 ms 73032 KB Output is correct
38 Correct 405 ms 79076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9676 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
3 Correct 6 ms 9676 KB Output is correct
4 Correct 6 ms 9676 KB Output is correct
5 Correct 6 ms 9768 KB Output is correct
6 Correct 6 ms 9728 KB Output is correct
7 Correct 6 ms 9800 KB Output is correct
8 Correct 6 ms 9732 KB Output is correct
9 Correct 6 ms 9804 KB Output is correct
10 Correct 7 ms 9732 KB Output is correct
11 Correct 7 ms 9804 KB Output is correct
12 Correct 6 ms 9804 KB Output is correct
13 Correct 6 ms 9804 KB Output is correct
14 Correct 6 ms 9732 KB Output is correct
15 Correct 6 ms 9804 KB Output is correct
16 Correct 6 ms 9804 KB Output is correct
17 Correct 6 ms 9724 KB Output is correct
18 Correct 6 ms 9716 KB Output is correct
19 Correct 6 ms 9724 KB Output is correct
20 Correct 7 ms 9728 KB Output is correct
21 Correct 6 ms 9804 KB Output is correct
22 Correct 353 ms 72888 KB Output is correct
23 Correct 347 ms 72772 KB Output is correct
24 Correct 348 ms 72388 KB Output is correct
25 Correct 350 ms 72380 KB Output is correct
26 Correct 347 ms 72244 KB Output is correct
27 Correct 386 ms 73048 KB Output is correct
28 Correct 382 ms 73156 KB Output is correct
29 Correct 407 ms 73028 KB Output is correct
30 Correct 393 ms 73052 KB Output is correct
31 Correct 350 ms 73028 KB Output is correct
32 Correct 391 ms 86652 KB Output is correct
33 Correct 375 ms 96836 KB Output is correct
34 Correct 335 ms 72808 KB Output is correct
35 Correct 338 ms 72992 KB Output is correct
36 Correct 373 ms 74712 KB Output is correct
37 Correct 359 ms 73032 KB Output is correct
38 Correct 405 ms 79076 KB Output is correct
39 Runtime error 266 ms 89512 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -