답안 #398145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398145 2021-05-03T19:53:25 Z 4fecta Meetings 2 (JOI21_meetings2) C++17
0 / 100
59 ms 125940 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)

const int MN = 4005;

int n, u, v, ans[MN], dep[MN], sz[MN], dist[MN][MN];
vector<int> a[MN];

void dfs(int cur, int par, int d) {
    sz[cur] = 1;
    dep[cur] = d;
    for (int nxt : a[cur]) {
        if (nxt == par) continue;
        dfs(nxt, cur, d + 1);
        sz[cur] += sz[nxt];
    }
}

int32_t main() {
    boost();

    memset(dist, 0x3f, sizeof(dist));
    cin >> n;
    for (int i = 1; i <= n; i++) dist[i][i] = 0;
    for (int i = 1; i < n; i++) {
        cin >> u >> v;
        dist[u][v] = dist[v][u] = 1;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        dfs(i, 0, 0);
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                if (i == j || i == k || dist[j][k] != dep[j] + dep[k]) continue;
                ans[min(sz[j], sz[k]) * 2] = max(ans[min(sz[j], sz[k]) * 2], dep[j] + dep[k] + 1);
            }
        }
    }
    for (int i = n; i > 0; i--) ans[i] = max({2ll, ans[i], ans[i + 1]});
    for (int i = 1; i <= n; i++) printf("%lld\n", i % 2 ? 1 : ans[i]);

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 125892 KB Output is correct
2 Correct 59 ms 125908 KB Output is correct
3 Correct 57 ms 125860 KB Output is correct
4 Correct 57 ms 125940 KB Output is correct
5 Incorrect 57 ms 125928 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 125892 KB Output is correct
2 Correct 59 ms 125908 KB Output is correct
3 Correct 57 ms 125860 KB Output is correct
4 Correct 57 ms 125940 KB Output is correct
5 Incorrect 57 ms 125928 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 125892 KB Output is correct
2 Correct 59 ms 125908 KB Output is correct
3 Correct 57 ms 125860 KB Output is correct
4 Correct 57 ms 125940 KB Output is correct
5 Incorrect 57 ms 125928 KB Output isn't correct
6 Halted 0 ms 0 KB -