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], num[DIM];
vector<int> v[DIM];
void dfs(int nod){
viz[nod] = num[nod] = 1;
for(int i = 0; i < v[nod].size(); i++){
int vecin = v[nod][i];
if(viz[vecin] == 0){
dfs(vecin);
num[nod] += num[vecin];
}
}
sum += num[nod];
}
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(num, 0, sizeof(num) );
memset(viz, 0, sizeof(viz) );
sum = 0;
dfs(i);
sol = min(sol, sum);
}
cout<< sol;
}
Compilation message (stderr)
bosses.cpp: In function 'void dfs(int)':
bosses.cpp:11: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... |