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>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N = 1e6+50, mod = 1e9+7, K = 31;
int n,k,x;
ll answer,res;
vector<int>gr[N];
bool fix[N];
int cnt = 0;
void dfs(int x,int h){
res += h;
cnt++;
fix[x] = 1;
for(auto to : gr[x]){
if(fix[to]) continue;
dfs(to,h+1);
}
}
inline void test_case(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> k;
for(int j = 1; j <= k; j++){
cin >> x;
//v[i].pb(x);
gr[x].pb(i);
}
}
ll answer = 1e18;
for(int i = 1; i <= n; i++){
dfs(i,1);
if(cnt == n)answer = min(answer, res);
res = 0;
cnt = 0;
for(int j = 1; j <= n; j++) fix[j] = 0;
}
cout << answer << endl;
}
main(){
ios::sync_with_stdio(0);
int T = 1;
//cin >> T;
for(int i = 1; i <= T; i++){
test_case();
}
}
Compilation message (stderr)
bosses.cpp:49:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | main(){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |