제출 #79523

#제출 시각아이디문제언어결과실행 시간메모리
79523Dat160601Bosses (BOI16_bosses)C++17
100 / 100
619 ms948 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back int n,x,u,v,ans=1e9; vector <int> edge[5007]; int vis[5007]; void go(int root){ queue <int> q; q.push(root); vis[root]=1; int ret=0, cnt=0; while(!q.empty()){ int u=q.front(); cnt++; q.pop(); ret+=vis[u]; for(int v:edge[u]){ if(!vis[v]){ vis[v]=vis[u]+1; q.push(v); } } } if(cnt==n) ans=min(ans,ret); } int main(){ ios_base::sync_with_stdio(0); cin>>n; for(int i=1;i<=n;i++){ cin>>x; while(x>0){ x--; cin>>v; edge[v].pb(i); } } for(int i=1;i<=n;i++){ memset(vis,0,sizeof(vis)); go(i); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...