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
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
vector<int> adj[5002];
int n;
pii dfs(int curr, vector<bool> &vis) {
vector<int> v;
for(int next:adj[curr]) {
if(!vis[next]) {
vis[next] = 1;
v.push_back(next);
}
}
pii ans = {0, 1};
for(int next:v) {
pii tmp = dfs(next, vis);
ans.f += tmp.f;
ans.s += tmp.s;
}
ans.f += ans.s;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(int i=1;i<=n;i++) {
int k, v;
cin>>k;
while(k--) {
cin>>v;
adj[v].push_back(i);
}
}
int ans = INT_MAX;
for(int root=1;root<=n;root++) {
vector<bool> vis(n+1, 0);
vis[root] = 1;
ans = min(ans, dfs(root, vis).f);
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |