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;
using nagai = long long;
using ll = long long;
const int N = 5000;
vector<int> g[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> 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);
}
}
int ans = 1e9;
for (int rt = 0; rt < n; ++rt)
{
vector<int> d(n, -1);
d[rt] = 1;
vector<int> q = {rt};
for (int i = 0; i < q.size(); ++i)
{
int x = q[i];
for (int y : g[x])
{
if (d[y] == -1)
d[y] = d[x] + 1, q.push_back(y);
}
}
if (count(d.begin(), d.end(), -1))
continue;
ans = min(ans, accumulate(d.begin(), d.end(), 0));
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'int main()':
bosses.cpp:34:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < q.size(); ++i)
~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |