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 <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=5005;
vector<int> adj[N];
bool mark[N];
int ans=0;
int cnt=0;
int gentree(int node){
mark[node]=true;
cnt++;
int sum=1;
for(int to : adj[node]){
if(!mark[to]){
sum+=gentree(to);
}
}
ans+=sum;
return sum;
}
void clearmark(int n){
for(int i=1; i<= n; i++){
mark[i]=0;
}
}
int main()
{
int n;
cin >> n;
for(int i=0; i< n; i++){
int k;
cin >> k;
for(int j=0; j< k; j++){
int kita;
cin >> kita;
adj[kita].pb(i+1);
}
}
int mn=1e9;
for(int i=1; i<=n; i++){
gentree(i);
if(cnt==n)mn=min(mn, ans);
clearmark(n+1);
cnt=0;
ans=0;
}
cout << mn << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |