Submission #46794

# Submission time Handle Problem Language Result Execution time Memory
46794 2018-04-23T10:23:45 Z oTTo_22 Bosses (BOI16_bosses) C++17
100 / 100
1138 ms 1332 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;
const int INF=1e9;

vector < vector < int > > g;

int main() {

    ios_base::sync_with_stdio(false);

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int n;
    cin >> n;

    g.resize(n+1);

    for (int i=1; i<=n; i++) {
        int k;
        cin >> k;
        while (k--) {
            int a;
            cin >> a;
            g[a].push_back(i);
        }
    }

    /*for (int i=1; i<=n; i++) {
        for (int j=0; j<g[i].size(); j++)
            cout << g[i][j] << " ";
        cout << "\n";
    }*/

    int ans=INF;

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

        stack < pair < int,int > > st;
        queue < pair < int,int > > q;
        vector < bool > used(n+1,0);
        vector < int > vc(n+1,0);

        q.push({i,-1});
        used[i]=1;

        while (!q.empty()) {
            pair < int,int > v=q.front();
            //cout << i << "->" << v.fi << " " << v.se << "\n";
            st.push(v);
            q.pop();
            for (int i=0; i<g[v.fi].size(); i++) {
                int to=g[v.fi][i];
                if (!used[to]) {
                    used[to]=1;
                    q.push({to,v.fi});
                }
            }
        }

        while (!st.empty()) {
            pair < int,int > v=st.top();
            st.pop();
            if (!st.empty()) {
                vc[v.fi]++;
                vc[v.se]+=vc[v.fi];
            }
            else
                vc[v.fi]++;
        }

        int cnt=0;
        bool ind=0;

        for (int i=1; i<=n; i++) {
            if (!vc[i]) {
                ind=1;
                break;
            }
            cnt+=vc[i];
        }

        if (!ind)
            ans=min(ans,cnt);

    }

    cout << ans;

    return 0;
}

Compilation message

bosses.cpp: In function 'int main()':
bosses.cpp:55:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i=0; i<g[v.fi].size(); i++) {
                           ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 716 KB Output is correct
6 Correct 2 ms 716 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 716 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 9 ms 808 KB Output is correct
13 Correct 7 ms 844 KB Output is correct
14 Correct 235 ms 1012 KB Output is correct
15 Correct 19 ms 1044 KB Output is correct
16 Correct 854 ms 1148 KB Output is correct
17 Correct 1138 ms 1268 KB Output is correct
18 Correct 1049 ms 1332 KB Output is correct