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;
vector<int> haha[5001];
int n;
int calc(int s) {
vector<int> ans(n+1,INT_MAX);
ans[s] = 0;
queue<int> idk;
idk.push(s);
while(!idk.empty()) {
int a = idk.front();
idk.pop();
for(int v: haha[a]) {
if(ans[v] > ans[a]+1) {
ans[v] = ans[a]+1;
idk.push(v);
}
}
}
int sb = 0;
for(int i = 1; i <= n; i++) {
if(ans[i] == INT_MAX) {
return INT_MAX;
}
sb+=ans[i]+1;
}
return sb;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
int k,a;
for(int i = 1; i <= n; i++) {
cin >> k;
for(int j = 0; j < k; j++) {
cin >> a;
haha[a].push_back(i);
}
}
int ans = INT_MAX;
for(int i = 1; i <= n; i++) {
ans = min(ans,calc(i));
}
cout << ans;
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... |