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;
#define int long long
int N, A = 1e9, T;
bitset<5005> V;
vector<int> adj[5005], nadj[5005];
queue<int> Q;
int dfs(int n, int e) {
int d = 1;
for (auto u : nadj[n])
if (u ^ e) d += dfs(u, n);
T += d;
return d;
}
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 1, K, X; i <= N; i++) {
cin >> K;
while (K--) {
cin >> X;
adj[X].push_back(i);
}
}
for (int i = 1; i <= N; i++) {
V.reset();
T = 0;
for (int j = 1; j <= N; j++) nadj[j].clear();
Q.push(i);
V[i] = 1;
while (!Q.empty()) {
int a = Q.front();
Q.pop();
for (auto u : adj[a])
if (!V[u]) {
V[u] = 1;
nadj[a].push_back(u);
Q.push(u);
}
}
if ((int)V.count() ^ N) continue;
dfs(i, -1);
A = min(A, T);
}
cout << A << '\n';
}
Compilation message (stderr)
bosses.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |