Submission #700880

# Submission time Handle Problem Language Result Execution time Memory
700880 2023-02-19T10:11:23 Z Makarooni Bosses (BOI16_bosses) C++17
100 / 100
1373 ms 944 KB
#include <bits/stdc++.h>
using namespace std;

#define pb(x) push_back(x)
typedef long long ll;

const int N = 5e3 + 10;
const int inf = 1e9;

vector<int> g[N], G[N];
int dis[N], ans[N];

void dfs(int v){
    ans[v] = 1;
    for(int u : G[v]){
        dfs(u);
        ans[v] += ans[u];
    }
}

int main(){
    int n;
    cin >> n;
    int k, v;
    for(int i = 1; i <= n; i++){
        cin >> k;
        for(int j = 1; j <= k; j++){
            cin >> v;
            g[v].pb(i);
        }
    }
    ll Ans = inf;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            dis[j] = inf;
            G[j].clear();
            ans[j] = inf;
        }
        queue<int> q;
        dis[i] = 0;
        q.push(i);
        while(!q.empty()){
            v = q.front();
            q.pop();
            for(int u : g[v]){
                if(dis[u] == inf){
                    dis[u] = dis[v] + 1;
                    G[v].pb(u);
                    q.push(u);
                }
            }
        }
        dfs(i);
        ll sal = 0;
        for(int j = 1; j <= n; j++)
            sal += ans[j];
        Ans = min(Ans, sal);
    }
    cout << Ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 544 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 544 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 5 ms 596 KB Output is correct
13 Correct 5 ms 616 KB Output is correct
14 Correct 305 ms 808 KB Output is correct
15 Correct 36 ms 724 KB Output is correct
16 Correct 1053 ms 896 KB Output is correct
17 Correct 1373 ms 940 KB Output is correct
18 Correct 1373 ms 944 KB Output is correct