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;
///10:45
typedef long long ll;
const int Nmax = 5005;
vector<int> v[Nmax];
int n, d[Nmax];
ll solve(int start)
{
queue<int> q;
memset(d, 0, sizeof(d));
q.push(start);
d[start] = 1;
ll ans = 1;
while(q.size())
{
int node = q.front();
q.pop();
for(auto it : v[node])
if(!d[it])
{
d[it] = d[node] + 1;
ans += d[it];
q.push(it);
}
}
return ans;
}
int main()
{
// freopen("input", "r", stdin);
cin.sync_with_stdio(false); cin.tie(0);
cin >> n;
int i;
for(i=1; i<=n; ++i)
{
int nr;
cin >> nr;
while(nr--)
{
int x;
cin >> x;
v[x].push_back(i);
}
}
ll ans = LLONG_MAX;
for(i=1; i<=n; ++i)
ans = min(ans, solve(i));
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... |