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], t[DIM];
vector<int> v[DIM];
void dfs(int nod){
viz[nod] = 1;
sum += niv[nod];
for(int i = 0; i < v[nod].size(); i++){
int vecin = v[nod][i];
if(viz[vecin] == 0){
viz[vecin] = 1;
niv[vecin] = 1 + niv[nod];
t[vecin] = nod;
}
}
for(int i = 0; i < v[nod].size(); i++){
int vecin = v[nod][i];
if(t[vecin] == nod){
dfs(vecin);
}
}
}
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) );
memset(t, 0, sizeof(t) );
niv[i] = 1;
t[i] = 0;
sum = 0;
dfs(i);
sol = min(sol, sum);
}
cout<< sol;
}
Compilation message (stderr)
bosses.cpp: In function 'void dfs(int)':
bosses.cpp:12:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v[nod].size(); i++){
~~^~~~~~~~~~~~~~~
bosses.cpp:20:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v[nod].size(); i++){
~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |