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<int> neww[5000];
int res;
int solve(int node) {
int r = 1;
for (int x : neww[node])
r += solve(x);
res += r;
return r;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, ans = 2e9;
cin >> n;
vector<int> adj[n];
bool v[n];
for (int i = 0; i < n; i++) {
int t;
cin >> t;
while (t--) {
int x;
cin >> x;
adj[x - 1].push_back(i);
}
}
for (int i = 0; i < n; i++) {
queue<int> q;
q.push(i);
memset(v, 0, sizeof v);
for (int i = 0; i < 5000; i++)
neww[i].clear();
int vis = 0;
v[i] = 1;
while (!q.empty()) {
int cur = q.front();
q.pop();
vis++;
for (int x : adj[cur])
if (!v[x])
neww[cur].push_back(x), q.push(x), v[x] = 1;
}
if (vis == n) {
res = 0;
solve(i);
ans = min(ans, res);
}
}
cout << ans << '\n';
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... |