답안 #398143

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398143 2021-05-03T19:50:13 Z 4fecta Meetings 2 (JOI21_meetings2) C++17
0 / 100
1 ms 1584 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 = 400;

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 == k || dist[j][k] != dep[j] + dep[k]) continue;
                if (i == j) {
                    int ts = 1;
                    for (int o = 1; o <= n; o++) if (dist[o][i] == 1 && dist[o][k] == dep[o] + dep[k]) ts = max(ts, sz[o] + 1);
                    ans[min(ts, sz[k]) * 2] = max(ans[min(ts, sz[k]) * 2], dep[j] + dep[k] + 1);
                } else 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(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 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1584 KB Output is correct
4 Incorrect 1 ms 1484 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1584 KB Output is correct
4 Incorrect 1 ms 1484 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1584 KB Output is correct
4 Incorrect 1 ms 1484 KB Output isn't correct
5 Halted 0 ms 0 KB -