Submission #1113083

#TimeUsernameProblemLanguageResultExecution timeMemory
1113083lucascgarBosses (BOI16_bosses)C++17
67 / 100
1553 ms1256 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;

const int MAXN = 5e3+10;

vector<int> ac[MAXN], b[MAXN];
long long cr = 0;
long long dfs(int x, vector<vector<int>> &f){
    if (f[x].empty()){
        cr++;
        return 1;
    }

    long long tt = 0;
    for (auto &i:f[x]){
        tt+=dfs(i, f);
    }
    cr+=tt+1;
    return tt+1;
}

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

    int n, k;
    cin >> n;

    for (int i=1;i<=n;i++){
        cin >> k;
        b[i].resize(k);
        for (auto &x:b[i]){
            cin >> x;
            ac[x].push_back(i);
        }
    }
    long long ans = 1e18+1;
    for (int b=1;b<=n;b++){
        vector<bool> v(n+1, 0);
        vector<vector<int>> f(n+1);

        queue<int> q;
        v[b] = 1;
        q.push(b);
        int tt = 0;
        while (!q.empty()){
            int u = q.front();
            tt++;
            q.pop();
            for (auto &i:ac[u]) if (!v[i]){
                v[i]=1;
                f[u].push_back(i);
                q.push(i);
            }
        }

        if (tt!=n) continue;
        cr = 0;
        dfs(b, f);
        ans = min(ans, cr);

    }

    cout << ans << '\n';

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...