제출 #991243

#제출 시각아이디문제언어결과실행 시간메모리
991243rsinventorBosses (BOI16_bosses)C++17
100 / 100
516 ms1112 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector <ll> vll;
typedef vector<bool> vb;
typedef vector <string> vs;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef vector <pii> vpii;

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define endl "\n"

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n;
    cin >> n;
    vector<ll> adj[n];
    for(ll i = 0; i < n; i++) {
        ll tmp;
        cin >> tmp;
        for(ll j = 0; j < tmp; j++) {
            ll a;
            cin >> a;
            adj[--a].pb(i);
        }
    }

    ll ans = 1e10;
    for(ll r = 0; r < n; r++) {
        vector<ll> lvl(n);
        queue<ll> q;

        lvl[r] = 1;
        q.push(r);
        while (!q.empty()) {
            ll i = q.front();
            q.pop();
            for (ll a: adj[i]) {
                if (lvl[a]==0) {
                    q.push(a);
                    lvl[a] = lvl[i] + 1;
                }
            }
        }
        ll sum = 0;
        bool flag = true;
        for(ll l: lvl) {
            if(l==0) {
                flag = false;
            }
            sum += l;
        }
        if(flag) {
            ans = min(ans, sum);
        }
    }

    cout << ans << endl;

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