Submission #868795

# Submission time Handle Problem Language Result Execution time Memory
868795 2023-11-02T02:52:23 Z garam1732 Meetings 2 (JOI21_meetings2) C++14
0 / 100
4 ms 17716 KB
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define bl " "
#define endl "\n"
#define all(v) v.begin(), v.end()
#define comp(v) v.erase(unique(all(v)), v.end())
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 200200;
const int MOD = 998244353;

vector<int> adj[MAXN];
map<int, int> mp[MAXN];
bool vst[MAXN];
int res[MAXN], mx[MAXN];
int dst[MAXN], cnt[MAXN];

void dfs1(int here, int par) {
    cnt[here] = 1;

    if(vst[here]) return;
    for(int there : adj[here]) {
        if(there == par) continue;

        dfs1(there, here);
        cnt[here] += cnt[there];
    }
}

void dfs2(int here, int par, int num) {
    cnt[here] = 1;

    if(!vst[here]) {
        for(int there : adj[here]) {
            if(there == par) continue;

            dst[there] = dst[here] + 1;
            dfs2(there, here, num);
            cnt[here] += cnt[there];
        }
    }

    mp[num][cnt[here]] = max(mp[num][cnt[here]], dst[here]);
}

void solve(int here) {
    dfs1(here, here);

    int n = cnt[here];
    for(int par = here; ; ) {
        bool flag = true;
        for(int there : adj[here]) {
            if(there == par || vst[there]) continue;
            if(cnt[there]*2 > n) {
                flag = false;
                par = here; here = there;
                break;
            }
        }

        if(flag) break;
    }

    for(int i = 0; i < adj[here].size(); i++) mp[i].clear();

    dst[here] = 0; int num = 0;
    for(int there : adj[here]) {
        dst[there] = dst[here] + 1;
        dfs2(there, here, num);

        for(int i = cnt[there]-1; i; i--)
            mp[num][i] = max(mp[num][i], mp[num][i+1]);

        num++;
    }

    for(int i = 1; i <= n; i++) {
        int a = -1, b = -1;
        for(int j = 0; j < num; j++) {
            if(mp[j].size() >= i) {
                int x = mp[j][i];
                if(a <= x) b = a, a = x;
                else if(b <= x) b = x;
            }
        }

        if(b == -1) break;
        res[i] = max(res[i], a+b+1);
    }

    vst[here] = 1;
    for(int there : adj[here]) {
        if(!vst[there])
            solve(there);
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int n; cin >> n;
    for(int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    dfs1(1, 1);
    int tmp = 0;
    for(int i = 2; i <= n; i++)
        tmp = max(tmp, min(cnt[i], n-cnt[i]));

    fill(res+1, res+n+1, 1);
    for(int i = 1; i <= tmp; i++) res[i] = 2;

    solve(1);
    for(int i = 1; i <= n; i++) cout << (i%2 ? 1 : res[i/2]) << endl;
}

Compilation message

meetings2.cpp: In function 'void solve(int)':
meetings2.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i = 0; i < adj[here].size(); i++) mp[i].clear();
      |                    ~~^~~~~~~~~~~~~~~~~~
meetings2.cpp:86:29: warning: comparison of integer expressions of different signedness: 'std::map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   86 |             if(mp[j].size() >= i) {
      |                ~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 17500 KB Output is correct
2 Correct 3 ms 17500 KB Output is correct
3 Correct 3 ms 17716 KB Output is correct
4 Correct 3 ms 17500 KB Output is correct
5 Correct 4 ms 17500 KB Output is correct
6 Correct 3 ms 17500 KB Output is correct
7 Correct 3 ms 17500 KB Output is correct
8 Correct 3 ms 17712 KB Output is correct
9 Correct 4 ms 17500 KB Output is correct
10 Correct 3 ms 17500 KB Output is correct
11 Incorrect 3 ms 17500 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 17500 KB Output is correct
2 Correct 3 ms 17500 KB Output is correct
3 Correct 3 ms 17716 KB Output is correct
4 Correct 3 ms 17500 KB Output is correct
5 Correct 4 ms 17500 KB Output is correct
6 Correct 3 ms 17500 KB Output is correct
7 Correct 3 ms 17500 KB Output is correct
8 Correct 3 ms 17712 KB Output is correct
9 Correct 4 ms 17500 KB Output is correct
10 Correct 3 ms 17500 KB Output is correct
11 Incorrect 3 ms 17500 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 17500 KB Output is correct
2 Correct 3 ms 17500 KB Output is correct
3 Correct 3 ms 17716 KB Output is correct
4 Correct 3 ms 17500 KB Output is correct
5 Correct 4 ms 17500 KB Output is correct
6 Correct 3 ms 17500 KB Output is correct
7 Correct 3 ms 17500 KB Output is correct
8 Correct 3 ms 17712 KB Output is correct
9 Correct 4 ms 17500 KB Output is correct
10 Correct 3 ms 17500 KB Output is correct
11 Incorrect 3 ms 17500 KB Output isn't correct
12 Halted 0 ms 0 KB -