Submission #1016780

# Submission time Handle Problem Language Result Execution time Memory
1016780 2024-07-08T12:13:37 Z inesfi Bosses (BOI16_bosses) C++14
100 / 100
1105 ms 1128 KB
#include<bits/stdc++.h>
using namespace std;

const int TAILLEMAXI=5002;
int nbpers,nbpos,val,taille,ec,pere,rep,total,pb;
vector<int> enfantspos[TAILLEMAXI];
vector<int> fils[TAILLEMAXI];
int dejapris[TAILLEMAXI];
deque<pair<int,int>> encours;

int trouver(int a){
    int somme;
    somme=0;
    for (int i=0;i<(int)fils[a].size();i++){
        somme+=trouver(fils[a][i]);
    }
    //cout<<a<<" "<<somme<<endl;
    somme++;
    total+=somme;
    return somme;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>nbpers;
    for (int i=1;i<=nbpers;i++){
        cin>>nbpos;
        for (int ipos=0;ipos<nbpos;ipos++){
            cin>>val;
            enfantspos[val].push_back(i);
        }
    }
    rep=TAILLEMAXI*TAILLEMAXI;
    for (int ideb=1;ideb<=nbpers;ideb++){
        for (int i=1;i<=nbpers;i++){
            fils[i].clear();
        }
        encours.push_back({ideb,0});
        while (encours.size()!=0){
            taille=encours.size();
            for (int i=0;i<taille;i++){
                ec=encours.front().first;
                pere=encours.front().second;
                encours.pop_front();
                if (dejapris[ec]!=ideb){
                    fils[pere].push_back(ec);
                    dejapris[ec]=ideb;
                    for (int ipos=0;ipos<(int)enfantspos[ec].size();ipos++){
                        if (dejapris[enfantspos[ec][ipos]]!=ideb){
                            encours.push_back({enfantspos[ec][ipos],ec});
                        }
                    }
                }
            }
        }
        pb=0;
        for (int i=1;i<=nbpers;i++){
            if (dejapris[i]!=ideb){
                pb=1;
            }
        }
        if (pb==0){
            //cout<<ideb<<endl;
            total=0;
            val=trouver(ideb);
            rep=min(rep,total);
            //cout<<total<<endl;
        }
    }
    cout<<rep<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 17 ms 852 KB Output is correct
13 Correct 11 ms 860 KB Output is correct
14 Correct 189 ms 900 KB Output is correct
15 Correct 44 ms 860 KB Output is correct
16 Correct 728 ms 1036 KB Output is correct
17 Correct 1105 ms 1128 KB Output is correct
18 Correct 1080 ms 1104 KB Output is correct