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>adje[5005];
bool vis[5005];
long long biy;
int ct;
void BFS(int x) {
queue<pair<int,int>> q;
q.push({x, 1});
vis[x]=true;
while(!q.empty()) {
int node = q.front().first;
int ting = q.front().second;
q.pop();
biy+=(ting*1ll);
ct++;
for (auto itr:adje[node]) {
if(vis[itr]) continue;
vis[itr]=true;
q.push({itr, ting+1});
}
}
}
int main() {
int N, t, a;
cin >> N;
for (int i=1; i<=N; i++) {
cin >> t;
for (int j=1; j<=t; j++) {
cin >> a;
adje[a].push_back(i);
}
}
long long jawab = 1e18;
for (int i=1; i<=N; i++) {
ct = 0;
biy = 0;
memset(vis, 0, sizeof(vis));
BFS(i);
if(ct!=N) continue;
jawab = min(jawab, biy);
}
cout << jawab << endl;
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... |