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 int long long
using namespace std;
vector<int> adj[10009], used(10009);
int ans = 0, anss = 0;
int dfs(int u){
int ans = 0;
for(int i: adj[u]){
if(!used[i]){
used[i] = 1;
ans += dfs(i) + 1;
}
}
anss += ans;
if(!ans) return 0;
return ans;
}
signed main(){
int n;
cin >> n;
for(int i = 0; i < n; i++){
int x; cin >> x;
for(int j = 0; j < x; j++){
int a;
cin >> a;
adj[a].push_back(i + 1);
}
}
int mn = INT_MAX;
for(int i = 1; i <= n; i++){
ans = 0, anss = 0;
dfs(i);
mn = min(anss, mn);
fill(used.begin(), used.end(), 0);
}
cout << mn;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |