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 <iostream>
#include <vector>
#include <queue>
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>>tabel;
vector<int>viz;
vector<int>pasi;
int cnt=0,stot=0;
void bfs(int nod){
queue<int>q;
viz[nod]=1;
q.push(nod);
pasi[nod]=1;
stot=1;
while(!q.empty()){
int curent=q.front();
q.pop();
for(auto i : tabel[curent])
if(!viz[i]){
viz[i]=1;///
pasi[i]=pasi[curent]+1;
stot+=pasi[i];
q.push(i);///
cnt++;///
}
}
}
/*
int dfs(int nod){
int sal=1;
for(auto i : tabel[nod])
if(pasi[i]-1==pasi[nod])
sal+=dfs(i);
stot+=sal;
return sal;
}
*/
int salmin=(1<<30);
int main()
{
int n;
cin>>n;
tabel.resize(n+2);
for(int i=1;i<=n;i++){
int k;
cin>>k;
for(int j=1;j<=k;j++){
int x;
cin>>x;
tabel[x].push_back(i);
}
}
for(int i=1;i<=n;i++){
viz.resize(n+2,0);
pasi.resize(n+2,0);
cnt=0;
stot=0;
bfs(i);
if(cnt==n-1){
salmin=min(salmin,stot);
}
}
cout<<salmin;
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... |