제출 #857844

#제출 시각아이디문제언어결과실행 시간메모리
857844vjudge1Bosses (BOI16_bosses)C++17
100 / 100
408 ms1028 KiB
#include <bits/stdc++.h> using namespace std; const int mxn=5e3+5; int n,ans[mxn],dis[mxn],sum; vector<int>v[mxn]; int main(){ cin>>n; for(int i=1;i<=n;i++){ int k; cin>>k; for(int j=1;j<=k;j++){ int x; cin>>x; v[x].push_back(i); } } int d=1e9; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++)dis[j]=0; sum=0; dis[i]=1; queue<int>q; q.push(i); while(q.size()){ int x=q.front(); ans[i]+=dis[x]; sum++; q.pop(); for(auto j:v[x]){ if(dis[j]==0)dis[j]=dis[x]+1,q.push(j); } } if(sum<n)ans[i]=1e9; d=min(ans[i],d); } cout<<d<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...