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 long long INF = (long long) 1e18;
int n;
vector< vector<int> > g;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
g.resize(n + 1);
for (int i = 1; i <= n; i++) {
int k;
cin >> k;
while (k--) {
int p;
cin >> p;
g[p].push_back(i);
}
}
long long ans = INF;
for (int i = 1; i <= n; i++) {
vector<int> d(n + 1, -1);
d[i] = 1;
priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > pq;
long long tmp = 1;
for (auto& v : g[i]) {
pq.push({1, v});
}
while (!pq.empty()) {
pair<int, int> cur = pq.top();
pq.pop();
if (d[cur.second] != -1) {
continue;
}
d[cur.second] = cur.first + 1;
tmp += (long long) d[cur.second];
for (auto& v : g[cur.second]) {
if (d[v] == -1) {
pq.push({d[cur.second], v});
}
}
}
ans = min(ans, tmp);
}
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... |