Submission #857344

# Submission time Handle Problem Language Result Execution time Memory
857344 2023-10-06T00:06:06 Z teesla Bosses (BOI16_bosses) C++17
0 / 100
0 ms 600 KB
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> adj;
vector<int> vis;

int res = 0;

void bfs(int x){

    queue<pair<int,int>> q;
    q.push({x,1});
    vis[x] = 1;

    while(!q.empty()){

        auto [a,b] = q.front();q.pop();
        if(vis[a]< b) continue;

        res += b;

        for(auto i: adj[a]){

            if(vis[i] != -1) continue;
            vis[i] = b + 1;
            q.push({i, vis[i]});
        }

    }
}

int main(){

    int n; cin >> n;
    adj.resize(n);

    for(int i=0; i<n; i++){

        int k; cin >> k;

        for(int j =0; j<k; j++){
            int a; cin >> a; a--;
            adj[a].push_back(i);
        }
    }

    int menor = -1;

    for(int i=0; i<n; i++){
        vis.assign(n,-1);

        res = 0;
        bfs(i);

        for(auto j: vis) if(j == -1) continue;
        if(menor == -1) menor =res;
        else menor = min(menor, res);
    }

    cout << menor << endl;

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -