Submission #723786

# Submission time Handle Problem Language Result Execution time Memory
723786 2023-04-14T10:03:37 Z rshohruh Bosses (BOI16_bosses) C++14
100 / 100
1486 ms 940 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
    
vector<vector<int>> dp1, dp2;
vector<bool> vis;
    
pair<int, int> dfs(int u){
    vis[u] = true;
    pair<int, int> res0 = {1, 0}, res1;
    for(int v : dp2[u]){
        res1 = dfs(v);
        res0.second += res1.second;
        res0.first += res1.first;
    }
    res0.second += res0.first;
    return res0;
}
    
int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n; cin >> n;
    dp1.resize(n);
    for(int i=0; i<n; ++i){
        int k; cin >> k;
        for(int j=0; j<k; ++j){
            int x; cin >> x;
            dp1[x-1].push_back(i);
        }
    }
    int ans = 1e18;
    for(int u=0; u<n; ++u){
        vis.assign(n, false);
        dp2.assign(n, {});
        queue<int> q;
        q.push(u);
        vis[u] = true;
        while(!q.empty()){
            int u = q.front(); q.pop();
            for(int v : dp1[u]){
                if(!vis[v]){
                    vis[v] = true;
                    q.emplace(v);
                    dp2[u].push_back(v);
                }
            }
        }
        bool f = true;
        for(int i=0; i<n; ++i) if(!vis[i]){
            f = false;
        }
        if(f) ans = min(ans, dfs(u).second);
    }
    cout << ans;
}	
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 5 ms 468 KB Output is correct
13 Correct 4 ms 592 KB Output is correct
14 Correct 270 ms 868 KB Output is correct
15 Correct 111 ms 764 KB Output is correct
16 Correct 725 ms 940 KB Output is correct
17 Correct 1486 ms 920 KB Output is correct
18 Correct 1416 ms 924 KB Output is correct