Submission #784113

#TimeUsernameProblemLanguageResultExecution timeMemory
784113KindaNamelessBosses (BOI16_bosses)C++14
0 / 100
1 ms340 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()

vector<int> adj[5001];
bool vis[5001];
int val, answer = 2e9;

void dfs(int cur, int depth = 1){
    val += depth;
    vis[cur] = 1;
    for(int ch : adj[cur]){
        if(vis[ch])continue;
        dfs(ch, depth + 1);
    }
}

void solve(){
    int n; cin >> n;

    for(int i = 1; i <= n; ++i){
        int k; cin >> k;
        for(int j = 1; j <= k; ++j){
            int x; cin >> x;
            adj[x].push_back(i);
        }
    }

    for(int i = 1; i <= n; ++i){
        fill(vis, vis + n + 1, 0);
        val = 0;
        dfs(i);
        answer = min(answer, val);
    }

    cout << answer;

    return;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int tc = 1; //cin >> tc;

    while(tc--){
        solve();
    }

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