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;
const int maxn = 5005, INF = 1e9;
int n, mark[maxn], val[maxn];
vector<int> ad[maxn];
void dfs(int v) {
mark[v] = 1;
for (int u: ad[v]) {
if (!mark[u]) {
dfs(u);
val[v] += val[u];
}
}
val[v]++;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
int t;
cin >> t;
for (int j = 1; j <= t; j++) {
int x;
cin >> x;
ad[x].push_back(i);
}
}
int ans = INF;
for (int i = 1; i <= n; i++) {
dfs(i);
int sum = 0;
for (int i = 1; i <= n; i++)
sum += val[i];
ans = min(ans, sum);
memset(val, 0, sizeof val);
memset(mark, 0, sizeof mark);
}
cout << ans;
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... |