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>
using namespace std;
using ll = long long;
vector<vector<int>>gp;
vector<int>vis;
vector<int> sub;
int ans = INT_MAX,cnt=0;
void dfs(int u){
for(int &i:gp[u]){
if(!vis[i]){
vis[i]=1;
dfs(i);
sub[u]+=sub[i];
}
}
cnt+=sub[u];
if(vis[u]==2){
ans = min(ans,cnt);
}
}
void solve(){
int n;
cin>>n;
gp = vector<vector<int>>(n);
for(int i =0;i<n;i++){
int x;
cin>>x;
while(x--){
int v;
cin>>v;
gp[--v].push_back(i);
}
}
for(int i = 0;i<n;i++){
vis = vector<int>(n);
sub = vector<int>(n,1);
vis[i]=2;
cnt = 0;
dfs(i);
}
cout<<ans<<endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
// ll t;cin>>t;while(t--)
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |