제출 #1171940

#제출 시각아이디문제언어결과실행 시간메모리
1171940JahonaliXBosses (BOI16_bosses)C++20
67 / 100
1594 ms1068 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef JahonaliX
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    #define int long long
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, z = LLONG_MAX;
    cin >> n;
    vector<vector<int>> a(n);
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        while (k--) {
            int x;
            cin >> x;
            x--;
            a[x].emplace_back(i);
        }
    }
    for (int i = 0; i < n; ++i) {
        vector<vector<int>> b(n);
        vector<bool> v(n);
        v[i] = true;
        queue<int> q;
        q.emplace(i);
        while (!q.empty()) {
            int x = q.front();
            q.pop();
            for (int j : a[x]) {
                if (v[j]) continue;
                q.emplace(j);
                v[j] = true;
                b[x].emplace_back(j);
            }
        }
        bool ok = true;
        for (int j = 0; j < n; ++j) ok &= v[j];
        if (ok) {
            vector<int> x(n, 1);
            function<int(int)> dfs = [&] (int i) -> int {
                for (int j : b[i]) x[i] += dfs(j);
                return x[i];
            };
            dfs(i);
            z = min(z, accumulate(x.begin(), x.end(), 0ll));
        }
    }
    cout << z;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...