Submission #884276

#TimeUsernameProblemLanguageResultExecution timeMemory
884276vjudge1Bosses (BOI16_bosses)C++17
0 / 100
1 ms604 KiB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

const int N = 5e3 + 10, INF = 1e9;

int n, ans = INF;
vector<int> G[N];

void bfs(int v) {
    queue<int> q;
    vector<int> h(N, INF), H(N, 0);
    int res = 0, ps = 0;
    h[v] = 0;
    q.push(v);
    while (q.size()) {
        int u = q.front();
        q.pop();
        for (auto e : G[u])
            if (h[u] + 1 < h[e]) {
                h[e] = h[u] + 1;
                q.push(e);
            }
    }
    for (int i = 0; i < n; i++) {
        if (h[i] == INF) continue;
        H[h[i]]++;
    }
    for (int i = n; i >= 0; i--)
        ps += H[i], res += ps;
    ans = min(ans, res);
}

int main() {
    ios:: sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        int m, x;
        cin >> m;
        for (int j = 0; j < m; j++) {
            cin >> x;
            G[--x].pb(i);
        }
    }
    for (int i = 0; i < n; i++) bfs(i);
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...