This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author: erray
#include<bits/stdc++.h>
using namespace std;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vector<int>> g(n);
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
for (int j = 0; j < k; ++j) {
int x;
cin >> x;
--x;
g[x].push_back(i);
}
}
long long ans = LLONG_MAX;
for (int i = 0; i < n; ++i) {
vector<bool> vis(n);
vector<long long> val(n, 1);
queue<pair<int, int>> que;
que.emplace(i, -1);
vector<pair<int, int>> ord;
vis[i] = true;
while (!que.empty()) {
int v = que.front().first;
ord.push_back(que.front());
que.pop();
for (auto u : g[v]) {
if (vis[u]) continue;
vis[u] = true;
que.emplace(u, v);
}
}
if ((int) ord.size() != n) continue;
reverse(ord.begin(), ord.end());
ord.pop_back();
bool ok = true;
for (auto v : ord) {
val[v.second] += val[v.first];
}
ans = min(ans, accumulate(val.begin(), val.end(), 0LL));
}
cout << ans << '\n';
}
Compilation message (stderr)
bosses.cpp: In function 'int main()':
bosses.cpp:44:10: warning: unused variable 'ok' [-Wunused-variable]
44 | bool ok = true;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |