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;
vector<vector<int> > g;
vector<int> p;
int n;
const int inf = 1e9;
void dfs(int u){
for(int v: g[u]){
if(p[v] == -1){
p[v] = 1;
dfs(v);
p[u] += p[v];
}
}
}
int res(int u){
p.assign(n+1, -1);
p[u] = 1;
dfs(u);
int ans = 0;
for(int i = 1; i <= n; ++i){
if(p[i] == -1) return inf;
ans += p[i];
}
return ans;
}
int main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin >> n;
g.resize(n+1);
for(int i = 1, k; i <= n; ++i){
cin >> k;
g[i].resize(k);
for(int j = 0; j < k; ++j)
cin >> g[i][j];
}
int ans = inf;
for(int u = 1; u <= n; ++u)
ans = min(ans, res(u));
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... |