답안 #852965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852965 2023-09-23T09:25:19 Z danikoynov Meetings 2 (JOI21_meetings2) C++14
20 / 100
790 ms 262144 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 2e5 + 10;

int n;
vector < int > adj[maxn];
int order[maxn], tin[maxn], tout[maxn];
int timer, depth[maxn], sub[maxn];

void euler(int v, int p)
{
    order[++ timer] = v;
    tin[v] = timer;

    sub[v] = 1;
    for (int u : adj[v])
    {
        if (u == p)
            continue;
        depth[u] = depth[v] + 1;
        euler(u, v);
        sub[v] += sub[u];
    }

    tout[v] = timer;
}

vector < int > path;
int max_chain[maxn], virtual_sub[maxn];
set < pair < int, int > > act[maxn];

void dfs(int v, int p)
{

    for (int u : adj[v])
    {
        if (u == p)
            continue;
        virtual_sub[v] = n - sub[u];
        dfs(u, v);


        for (pair < int, int > cur : act[v])
        {
            set < pair < int, int > > :: iterator it = act[u].lower_bound(cur);
            if (it != act[u].end())
            {
                int id = cur.first * 2;

                max_chain[id] = max(max_chain[id], cur.second + it -> second - 2 * depth[v]);
            }
        }

        for (pair < int, int > cur : act[u])
        {
            set < pair < int, int > > :: iterator it = act[v].lower_bound(cur);
            if (it != act[v].end())
            {

                int id = cur.first * 2;
                ///cout << "here " << v << " " << id << " " << cur.first << " " << cur.second << endl;
                max_chain[id] = max(max_chain[id], cur.second + it -> second - 2 * depth[v]);
            }

            int vir_sub = n - sub[u];
            int id = 2 * min(vir_sub, cur.first);
            max_chain[id] = max(max_chain[id], cur.second - depth[v]);
        }

        for (pair < int, int > cur : act[u])
        {
            set < pair < int, int > > :: iterator it = act[v].lower_bound(cur);
            if (it != act[v].end() && it -> second >= cur.second)
                continue;
            act[v].insert(cur);
            while(true)
            {
                it = act[v].find(cur);
                if (it == act[v].begin())
                    break;
                it = prev(it);
                if (it -> second <= cur.second)
                    act[v].erase(it);
                else
                    break;
            }
        }
    }


    pair < int, int > cur = {sub[v], depth[v]};
    set < pair < int, int > > :: iterator it = act[v].lower_bound(cur);
    if (it != act[v].end() && it -> second >= cur.second)
        return;
    act[v].insert(cur);
    while(true)
    {
        it = act[v].find(cur);
        if (it == act[v].begin())
            break;
        it = prev(it);
        if (it -> second <= cur.second)
            act[v].erase(it);
        else
            break;
    }



}
void solve()
{
    cin >> n;
    for (int i = 1; i < n; i ++)
    {
        int v, u;
        cin >> v >> u;
        adj[v].push_back(u);
        adj[u].push_back(v);
    }

    euler(1, 0);
    for (int i = 1; i <= n; i ++)
    {
        max_chain[i] = -1;
    }

    dfs(1, 0);

    for (int i = n; i > 0; i --)
    {
        max_chain[i] = max(max_chain[i], max_chain[i + 1]);
    }
    for (int i = 1; i <= n; i ++)
    {
        if (i % 2 == 1)
            cout << 1 << endl;
        else
            cout << max_chain[i] + 1 << endl;
    }
}

int main()
{
    speed();
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17752 KB Output is correct
2 Correct 3 ms 17752 KB Output is correct
3 Correct 3 ms 17752 KB Output is correct
4 Correct 3 ms 17752 KB Output is correct
5 Correct 3 ms 17752 KB Output is correct
6 Correct 3 ms 17752 KB Output is correct
7 Correct 3 ms 17756 KB Output is correct
8 Correct 4 ms 17756 KB Output is correct
9 Correct 4 ms 17752 KB Output is correct
10 Correct 3 ms 17756 KB Output is correct
11 Correct 3 ms 17752 KB Output is correct
12 Correct 3 ms 17752 KB Output is correct
13 Correct 3 ms 17752 KB Output is correct
14 Correct 3 ms 17756 KB Output is correct
15 Correct 3 ms 17752 KB Output is correct
16 Correct 4 ms 17756 KB Output is correct
17 Correct 4 ms 17752 KB Output is correct
18 Correct 4 ms 17752 KB Output is correct
19 Correct 4 ms 17752 KB Output is correct
20 Correct 3 ms 17752 KB Output is correct
21 Correct 4 ms 17756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17752 KB Output is correct
2 Correct 3 ms 17752 KB Output is correct
3 Correct 3 ms 17752 KB Output is correct
4 Correct 3 ms 17752 KB Output is correct
5 Correct 3 ms 17752 KB Output is correct
6 Correct 3 ms 17752 KB Output is correct
7 Correct 3 ms 17756 KB Output is correct
8 Correct 4 ms 17756 KB Output is correct
9 Correct 4 ms 17752 KB Output is correct
10 Correct 3 ms 17756 KB Output is correct
11 Correct 3 ms 17752 KB Output is correct
12 Correct 3 ms 17752 KB Output is correct
13 Correct 3 ms 17752 KB Output is correct
14 Correct 3 ms 17756 KB Output is correct
15 Correct 3 ms 17752 KB Output is correct
16 Correct 4 ms 17756 KB Output is correct
17 Correct 4 ms 17752 KB Output is correct
18 Correct 4 ms 17752 KB Output is correct
19 Correct 4 ms 17752 KB Output is correct
20 Correct 3 ms 17752 KB Output is correct
21 Correct 4 ms 17756 KB Output is correct
22 Correct 8 ms 18520 KB Output is correct
23 Correct 6 ms 18520 KB Output is correct
24 Correct 6 ms 18524 KB Output is correct
25 Correct 7 ms 18520 KB Output is correct
26 Correct 7 ms 18524 KB Output is correct
27 Correct 6 ms 18520 KB Output is correct
28 Correct 6 ms 18524 KB Output is correct
29 Correct 6 ms 18520 KB Output is correct
30 Correct 6 ms 18520 KB Output is correct
31 Correct 6 ms 18520 KB Output is correct
32 Correct 213 ms 86100 KB Output is correct
33 Correct 635 ms 222508 KB Output is correct
34 Correct 5 ms 18424 KB Output is correct
35 Correct 5 ms 18264 KB Output is correct
36 Correct 12 ms 21084 KB Output is correct
37 Correct 5 ms 18268 KB Output is correct
38 Correct 146 ms 65504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17752 KB Output is correct
2 Correct 3 ms 17752 KB Output is correct
3 Correct 3 ms 17752 KB Output is correct
4 Correct 3 ms 17752 KB Output is correct
5 Correct 3 ms 17752 KB Output is correct
6 Correct 3 ms 17752 KB Output is correct
7 Correct 3 ms 17756 KB Output is correct
8 Correct 4 ms 17756 KB Output is correct
9 Correct 4 ms 17752 KB Output is correct
10 Correct 3 ms 17756 KB Output is correct
11 Correct 3 ms 17752 KB Output is correct
12 Correct 3 ms 17752 KB Output is correct
13 Correct 3 ms 17752 KB Output is correct
14 Correct 3 ms 17756 KB Output is correct
15 Correct 3 ms 17752 KB Output is correct
16 Correct 4 ms 17756 KB Output is correct
17 Correct 4 ms 17752 KB Output is correct
18 Correct 4 ms 17752 KB Output is correct
19 Correct 4 ms 17752 KB Output is correct
20 Correct 3 ms 17752 KB Output is correct
21 Correct 4 ms 17756 KB Output is correct
22 Correct 8 ms 18520 KB Output is correct
23 Correct 6 ms 18520 KB Output is correct
24 Correct 6 ms 18524 KB Output is correct
25 Correct 7 ms 18520 KB Output is correct
26 Correct 7 ms 18524 KB Output is correct
27 Correct 6 ms 18520 KB Output is correct
28 Correct 6 ms 18524 KB Output is correct
29 Correct 6 ms 18520 KB Output is correct
30 Correct 6 ms 18520 KB Output is correct
31 Correct 6 ms 18520 KB Output is correct
32 Correct 213 ms 86100 KB Output is correct
33 Correct 635 ms 222508 KB Output is correct
34 Correct 5 ms 18424 KB Output is correct
35 Correct 5 ms 18264 KB Output is correct
36 Correct 12 ms 21084 KB Output is correct
37 Correct 5 ms 18268 KB Output is correct
38 Correct 146 ms 65504 KB Output is correct
39 Correct 204 ms 47184 KB Output is correct
40 Correct 200 ms 49236 KB Output is correct
41 Correct 235 ms 49768 KB Output is correct
42 Correct 229 ms 50652 KB Output is correct
43 Correct 238 ms 50636 KB Output is correct
44 Correct 207 ms 50348 KB Output is correct
45 Runtime error 790 ms 262144 KB Execution killed with signal 9
46 Halted 0 ms 0 KB -