This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define OYY 1000000005
#define mod 1000000007
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mid (start+end)/2
#define lim 100005
vector<int> v[lim];
int dis[lim],n,vis[lim];
inline int bfs(int node){
for (int i=1;i<=n;i++){
dis[i]=OYY;
vis[i]=0;
}
priority_queue <pair<int,int>> pq;
pq.push({1,node});
dis[node]=1;
vis[node]=1;
//cout<<node<<" "<<dis[node]<<endl;
while(!pq.empty()){
int nd=pq.top().second;
pq.pop();
// cout<<pq.top().first<<" "<<pq.top().second<<" "<<dis[nd]<<endl;
for(int i=0;i<v[nd].size();i++){
if(vis[v[nd][i]])continue;
dis[v[nd][i]]=min(dis[v[nd][i]],dis[nd]+1);
vis[v[nd][i]]=1;
pq.push({-dis[v[nd][i]],v[nd][i]});
}
}
int cev=0;
for(int i=1;i<=n;i++){
cev+=dis[i];
}
// cout<<cev<<endl;
return cev;
}
int main(){
faster
cin>>n;
for(int i=1;i<=n;i++){
int deg,tut;cin>>deg;
for(int j=0;j<deg;j++){
cin>>tut;
v[tut].push_back(i);
}
}
int cev=OYY;
for(int i=1;i<=n;i++){
cev=min(cev,bfs(i));
}
cout<<cev<<'\n';
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'int bfs(int)':
bosses.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i=0;i<v[nd].size();i++){
| ~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |