# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163684 | alexandra_udristoiu | Bosses (BOI16_bosses) | C++14 | 897 ms | 860 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<vector>
#include<cstring>
#define DIM 5005
using namespace std;
int n, i, j, m, x, sum, sol;
int viz[DIM], niv[DIM], c[DIM];
vector<int> v[DIM];
void bfs(int srs){
int nod, vecin, i, j, p, u;
p = u = viz[srs] = 1;
c[1] = srs;
niv[srs] = 1;
while(p <= u){
nod = c[p];
sum += niv[nod];
p++;
for(j = 0; j < v[nod].size(); j++){
vecin = v[nod][j];
if(viz[vecin] == 0){
viz[vecin] = 1;
niv[vecin] = 1 + niv[nod];
c[++u] = vecin;
}
}
}
if(u != n){
sum = 1000000000;
}
}
int main(){
cin>> n;
for(i = 1; i <= n; i++){
cin>> m;
for(j = 1; j <= m; j++){
cin>> x;
v[x].push_back(i);
}
}
sol = 1000000000;
for(i = 1; i <= n; i++){
memset(viz, 0, sizeof(viz) );
sum = 0;
bfs(i);
sol = min(sol, sum);
}
cout<< sol;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |