Submission #991318

# Submission time Handle Problem Language Result Execution time Memory
991318 2024-06-02T01:34:15 Z 12345678 Meetings 2 (JOI21_meetings2) C++17
100 / 100
212 ms 27220 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=2e5+5;

int n, u, v, sz[nx], lvl[nx], mx[nx], res[nx], used[nx];
vector<int> d[nx];
pair<int, int> dp[nx];

void dfs(int u, int p)
{
    lvl[u]=lvl[p]+1;
    sz[u]=1;
    for (auto v:d[u]) if (v!=p&&!used[v]) dfs(v, u), sz[u]+=sz[v];
    mx[sz[u]]=max(mx[sz[u]], lvl[u]);
}

int dfssz(int u, int p)
{
    sz[u]=1;
    for (auto v:d[u]) if (v!=p&&!used[v]) sz[u]+=dfssz(v, u);
    return sz[u];
}

int findcentroid(int u, int p, int rtsz)
{
    for (auto v:d[u]) if (v!=p&&!used[v]&&2*sz[v]>rtsz) return findcentroid(v, u, rtsz);
    return u;
}

void decomposition(int u)
{
    u=findcentroid(u, u, dfssz(u, u));
    used[u]=1;
    int sm=sz[u];
    for (int i=1; i<=sm; i++) dp[i]={-1, -1};
    for (auto v:d[u])
    {
        if (used[v]) continue;
        lvl[v]=0;
        dfs(v, v);
        for (int i=sz[v]; i>=1; i--) 
        {
            mx[i]=max(mx[i], mx[i+1]);
            //cout<<"mx "<<v<<' '<<u<<' '<<i<<' '<<mx[i]<<'\n';
            if (mx[i]==0) continue;
            if (dp[i].first==-1||dp[i].first<mx[i]) swap(dp[i].first, dp[i].second), dp[i].first=mx[i];
            else if (dp[i].second==-1||mx[i]>dp[i].second) dp[i].second=mx[i];
        }
        for (int i=1; i<=sz[v]; i++) mx[i]=0;
    }
    for (int i=1; i<=sm; i++)
    {
        //cout<<"debug "<<u<<' '<<i<<' '<<dp[i].first<<' '<<dp[i].second<<'\n';
        if (dp[i].first!=-1&&dp[i].second==-1) res[i]=max(res[i], dp[i].first);
        else if (dp[i].first!=-1&&dp[i].second!=-1) res[i]=max(res[i], dp[i].first+dp[i].second);
    }
    for (auto v:d[u]) if (!used[v]) decomposition(v);
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u);
    decomposition(1);
    for (int i=1; i<=n; i++) cout<<((i%2)?1:(res[i/2]+1))<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6556 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6572 KB Output is correct
17 Correct 1 ms 6548 KB Output is correct
18 Correct 2 ms 6488 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6556 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6572 KB Output is correct
17 Correct 1 ms 6548 KB Output is correct
18 Correct 2 ms 6488 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 3 ms 6716 KB Output is correct
23 Correct 3 ms 6748 KB Output is correct
24 Correct 3 ms 6712 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 3 ms 6628 KB Output is correct
28 Correct 3 ms 6724 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 3 ms 6748 KB Output is correct
31 Correct 3 ms 6748 KB Output is correct
32 Correct 4 ms 6744 KB Output is correct
33 Correct 3 ms 6884 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6744 KB Output is correct
36 Correct 3 ms 6744 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 3 ms 6884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6556 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6572 KB Output is correct
17 Correct 1 ms 6548 KB Output is correct
18 Correct 2 ms 6488 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 3 ms 6716 KB Output is correct
23 Correct 3 ms 6748 KB Output is correct
24 Correct 3 ms 6712 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 3 ms 6628 KB Output is correct
28 Correct 3 ms 6724 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 3 ms 6748 KB Output is correct
31 Correct 3 ms 6748 KB Output is correct
32 Correct 4 ms 6744 KB Output is correct
33 Correct 3 ms 6884 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6744 KB Output is correct
36 Correct 3 ms 6744 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 3 ms 6884 KB Output is correct
39 Correct 143 ms 18880 KB Output is correct
40 Correct 133 ms 18452 KB Output is correct
41 Correct 140 ms 18772 KB Output is correct
42 Correct 133 ms 19048 KB Output is correct
43 Correct 132 ms 19020 KB Output is correct
44 Correct 131 ms 18896 KB Output is correct
45 Correct 212 ms 23380 KB Output is correct
46 Correct 194 ms 27220 KB Output is correct
47 Correct 64 ms 18632 KB Output is correct
48 Correct 62 ms 18880 KB Output is correct
49 Correct 121 ms 19792 KB Output is correct
50 Correct 64 ms 19660 KB Output is correct
51 Correct 123 ms 25544 KB Output is correct