제출 #857876

#제출 시각아이디문제언어결과실행 시간메모리
857876vjudge1Bosses (BOI16_bosses)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
const int maxn = 5e3 + 5;

bool mark[maxn];
int cnt[maxn], H_cnt[maxn], n;
vector<pii > P_pars;

int calc(int root) {
    vector<int> height[maxn];
    memset(H_cnt, 0, sizeof H_cnt);
    memset(mark, false, sizeof mark);
    height[0].pb(root);
    H_cnt[0] = 1;
    mark[root] = true;
    ll sum = n, dec = 1;
    for (int i = 1; i < n; i++) {
        for (int x: height[i - 1]) {
            for (pii u: P_pars) {
                int v = u.first, par = u.second;
                if (par == x and v != x and !mark[v]) {
                    height[i].pb(v);
                    H_cnt[i]++;
                    mark[v] = true;
                }
            }
        }
        sum += n - dec;
        dec += H_cnt[i];
    }
    return sum;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int mx = 0;
    vector<int> roots;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int c;
        cin >> c;
        for (int j = 1; j <= c; j++) {
            int x;
            cin >> x;
            P_pars.pb({i, x});
            cnt[x]++;
            if (cnt[x] == mx) {
                roots.pb(x);
            } else if (cnt[x] > mx) {
                mx = cnt[x];
                roots.clear();
                roots.pb(x);
            }
        }
    }
    int ans = 0;
    for (int r: roots) {
        ans = max(ans, calc(r));
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...