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 ll long long
using namespace std;
const int INF=1e9;
vector<vector<int>>v,g;
vector<bool>vis;
vector<int>a;
int n;
void dfs(int x){
vis[x]=true;
int s=0;
for(int z:v[x]){
if(!vis[z]){
g[x].push_back(z);
dfs(z);
s+=a[z];
}
}
a[x]+=s;
}
int solve(int x){
g.resize(n+1);
vis.assign(n+1,false);
a.assign(n+1,1);
dfs(x);
int s=0;
for(int i=1;i<=n;i++) s+=a[i];
return s;
}
int main(){
cin>>n;
v.resize(n+1);
for(int i=1;i<=n;i++){
int k;cin>>k;
for(int j=0;j<k;j++){
int x;cin>>x;
v[x].push_back(i);
}
}
int res=INF;
for(int i=1;i<=n;i++){
res=min(res,solve(i));
}
cout<<res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |