Submission #938832

# Submission time Handle Problem Language Result Execution time Memory
938832 2024-03-05T15:46:00 Z Darren0724 Bosses (BOI16_bosses) C++17
100 / 100
429 ms 848 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=5005;
const int INF=1e9;
int32_t main() {
    LCBorz;
    int n;cin>>n;
    vector<int> adj[N];
    for(int i=1;i<=n;i++){
        int k;cin>>k;
        for(int j=0;j<k;j++){
            int p;cin>>p;
            adj[p].push_back(i);
        }
    }
    auto bfs=[&](int s)->int {
        vector<int> dis(N,INF);
        queue<int> q;
        q.push(s);
        dis[s]=0;
        int ans=0,cnt=0;
        while(q.size()){
            int p=q.front();
            q.pop();
            ans+=dis[p];
            cnt++;
            for(int j:adj[p]){
                if(dis[j]==INF){
                    dis[j]=dis[p]+1;
                    q.push(j);
                }
            }
        }
        if(cnt==n)return ans+n;
        return INF;
    };
    int ans=INF;
    for(int i=1;i<=n;i++){
        ans=min(ans,bfs(i));
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 572 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 572 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 4 ms 604 KB Output is correct
14 Correct 95 ms 696 KB Output is correct
15 Correct 10 ms 604 KB Output is correct
16 Correct 416 ms 764 KB Output is correct
17 Correct 423 ms 848 KB Output is correct
18 Correct 429 ms 604 KB Output is correct