Submission #747990

#TimeUsernameProblemLanguageResultExecution timeMemory
747990vjudge1Bosses (BOI16_bosses)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; using ll=long long; const int maxn=5001; int n; vector<int> g[maxn]; ll bfs(int s){ queue<int> q; ll d[maxn]; d[s]=1; q.push(s); ll sum=0, cnt=1; while(!q.empty()){ int x=q.front(); q.pop(); sum += d[x]; for(int i:g[x]){ if(!d[i]){ cnt++; d[i]=d[x]+1; q.push(i); } } } return cnt==n?sum:LLONG_MAX; } int main() { cin >> n; for(int i=1;i<=n;i++){ int k; cin>>k; for(int j=0;j<k;j++) { int x; cin>>x; g[x].push_back(i); } } ll ans=LLONG_MAX; for(int i=1;i<=n;i++){ ans=min(ans, bfs(i)); } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...