제출 #484675

#제출 시각아이디문제언어결과실행 시간메모리
484675phamhoanghiepBosses (BOI16_bosses)C++14
100 / 100
623 ms648 KiB
#include<bits/stdc++.h> using namespace std; const int maxn=5005; vector<int> AdjList[maxn]; int dist[maxn]; int n; int bfs(int s) { //cout<<"bfs "<<s<<endl; int cnt=0; int ans=0; queue<int> q; q.push(s); dist[s]=1; while(!q.empty()) { int u=q.front(); //cout<<"u = "<<u<<endl; q.pop(); ans+=dist[u]; cnt++; for(int v: AdjList[u]) { //cout<<"dist "<<v<<" = "<<dist[v]<<endl; if(!dist[v]) { dist[v]=dist[u]+1; //cout<<"push "<<v<<endl; q.push(v); } } } if(cnt!=n) return 5000*5000; else return ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; for(int i=1 ; i<=n ; i++) { int k,u; cin>>k; for(int j=1 ; j<=k ; j++) { cin>>u; AdjList[u].push_back(i); //cout<<"Adj "<<u<<" "<<i<<endl; } } int ans=5000*5000; for(int root=1 ; root<=n ; root++) { for(int i=1 ; i<=n ; i++) dist[i]=0; ans=min(ans,bfs(root)); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...