답안 #893376

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893376 2023-12-27T03:39:21 Z vjudge1 Meetings 2 (JOI21_meetings2) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    vector <vector<int>> G(n);
    for ( int i = 1; i < n; i++ ){
        int u, v; cin >> u >> v;
        --u, --v;
        G[u].pb(v), G[v].pb(u);
    }
    vector <vector<int>> s(n, vector <int> (n)), d(n, vector <int> (n));
    for ( int i = 0; i < n; i++ ){
        auto dfs = [&](auto dfs, int u, int p) -> void{
            s[i][u] = 1;
            for ( auto &v: G[u] ){
                if ( v != p ){
                    d[i][v] = d[i][u] + 1;
                    dfs(dfs, v, u);
                    s[i][u] += s[i][v];
                }
            }
        };
        dfs(dfs, i, -1);
    }
    vector <int> ans(n + 1);
    const int S = 1 << n;
    for ( int mask = 0; mask < S; mask++ ){
        vector <int> a;
        for ( int i = 0; i < n; i++ ){
            if ( mask >> i & 1 ){
                a.pb(i);
            }
        }
        map <int,int> mp;
        for ( int rt = 0; rt < n; rt++ ){
            int cnt = 0;
            for ( auto &u: a ){
                cnt += d[rt][u];
            } mp[cnt]++;
        }
        chmax(ans[__builtin_popcount(mask)], mp.begin()->second);
    }
    for ( auto &i: ans ){
        cout << i << ln;
    }

    cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -