Submission #843787

# Submission time Handle Problem Language Result Execution time Memory
843787 2023-09-04T14:56:13 Z Cookie Meetings 2 (JOI21_meetings2) C++14
0 / 100
2 ms 5548 KB
#include<bits/stdc++.h>
#define ll long long
#define vt vector
#define pb push_back
#define sz(v) (int)v.size()
using namespace std;
const ll base = 107, mod = 1e9 + 7;
const int mxn = 1e5 + 5, inf = 1e9, sq = 400;
int n;
vt<int>adj[mxn + 1];
int tin[mxn + 1], tout[mxn + 1], tt = 0;
int dep[mxn + 1], up[mxn + 1][17], to[mxn + 1], ans[mxn + 1], sz[mxn + 1];
bool vis[mxn + 1];
void dfs_lca(int s, int pre){
    for(auto i: adj[s]){
        if(i != pre){
            dep[i] = dep[s] + 1; up[i][0] = s;
            dfs_lca(i, s);
        }
    }
}
 
int lca(int u, int v){
    if(dep[u] < dep[v])swap(u, v);
    int k = dep[u] - dep[v];
    for(int i = 0; i < 17; i++){
        if(k & (1 << i)){
            u = up[u][i]; 
        }
    }
    if(u == v)return(u);
    for(int i = 16; i >= 0; i--){
        if(up[u][i] != up[v][i]){
            u = up[u][i]; v = up[v][i];
        }
    }
    return(up[u][0]);
}
int dist(int u, int v){
    return(dep[u] + dep[v] - 2 * dep[lca(u, v)]);
}
void dfs_euler(int s, int pre){
    tin[s] = ++tt; sz[s] = 1;
    for(auto i: adj[s]){
        if(i != pre){
            dfs_euler(i, s); sz[s] += sz[i];
        }
    }
    tout[s] = tt;
 
}
bool inside(int u, int v){
    return(tin[u] <= tin[v] && tout[v] <= tout[u]);
}
void dfs(int s, int pre){
    for(int i = 1; i <= n; i++){
        if(inside(s, i))continue;
        if(vis[i]){
            int other = n - sz[to[i]];
            if(other > sz[s])continue;
            ans[min(other, sz[s])] = max(ans[min(other, sz[s])], dist(s, i) + 1);
        }else{
            int other = sz[i];
            if(other > sz[s])continue;
            ans[min(other, sz[s])] = max(ans[min(other, sz[s])], dist(s, i) + 1);
        }
    }
    vis[s] = 1;
    for(auto i: adj[s]){
        if(i != pre){
            to[s] = i;
            dfs(i, s);
        }
    }
    vis[s] = 0;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i < n; i++){
        int u, v; cin >> u >> v;
        adj[u].pb(v); adj[v].pb(u);
    }
    dfs_euler(1, -1);
    dfs_lca(1, -1);
    for(int i = 1; i < 17; i++){
        for(int j = 1; j <= n; j++){
            up[j][i] = up[up[j][i - 1]][i - 1];
        }
    }
    
    dfs(1, -1);
    for(int i = n / 2; i >= 1; i--){
        ans[i] = max(ans[i + 1], ans[i]);
    }
    for(int i = 1; i <= n; i++){
        if(i & 1)cout << 1 << "\n";
        else cout << max(1, ans[i / 2]) << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 5468 KB Output is correct
3 Correct 1 ms 5548 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Incorrect 1 ms 5468 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 5468 KB Output is correct
3 Correct 1 ms 5548 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Incorrect 1 ms 5468 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 5468 KB Output is correct
3 Correct 1 ms 5548 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Incorrect 1 ms 5468 KB Output isn't correct
6 Halted 0 ms 0 KB -