This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define li long int
#define ld long double
#define append push_back
#define add insert
#define nl '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define pic pair<int,char>
#define all(x) (x).begin(),(x).end()
#define sum(a) accumulate(all(a),0)
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define terminator main
#define N 5001
int n;
int vis[N];
vector<int> a[N];
ll bfs(int x){
ll o,r;
o=0;
vis[x]=r=1;
vector<int> v{x},u;
while(!v.empty()){
o+=r*v.size();
for(auto& i:v){
for(auto& j:a[i]){
if(vis[j]) continue;
u.append(j);
vis[j]=1;
}
}
swap(v,u);
u.clear();
r++;
}
for(int i=1;i<=n;i++)
vis[i]=0;
return o;
}
void solve(){
ll o;
int m;
cin>>n;
for(int i=1;i<=n;i++){
cin>>m;
while(m--){
cin>>o;
a[o].append(i);
}
}
o=1e17;
for(int i=1;i<=n;i++)
o=min(o,bfs(i));
cout<<o;
}
int terminator(){
L0TA;
solve();
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... |