Submission #784116

# Submission time Handle Problem Language Result Execution time Memory
784116 2023-07-15T17:48:07 Z KindaNameless Bosses (BOI16_bosses) C++14
100 / 100
392 ms 716 KB
#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 n, val, answer = 2e9;

void bfs(int cur){
    queue<pair<int, int>> q;

    vis[cur] = 1;
    q.push({cur, 1});

    int cnt = 0;
    while(!q.empty()){
        pair<int, int> now = q.front(); q.pop();
        cnt++;

        val += now.second;

        for(int nx : adj[now.first]){
            if(!vis[nx]){
                vis[nx] = 1;
                q.push({nx, now.second + 1});
            }
        }
    }

    if(cnt < n)val = 2e9;
}

void solve(){
    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;
        bfs(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 time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 100 ms 544 KB Output is correct
15 Correct 2 ms 456 KB Output is correct
16 Correct 392 ms 628 KB Output is correct
17 Correct 389 ms 716 KB Output is correct
18 Correct 387 ms 648 KB Output is correct