Submission #695168

#TimeUsernameProblemLanguageResultExecution timeMemory
695168Ahmed57Bosses (BOI16_bosses)C++14
100 / 100
580 ms580 KiB
#include <bits/stdc++.h> //#include "game.h" using namespace std; vector<int> v[5001]; long long all = 0; int main(){ //ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin>>n; for(int i = 1;i<=n;i++){ int k; cin>>k; for(int j = 0;j<k;j++){ int x;cin>>x; v[x].push_back(i); } } long long ans = 1e18; for(int i = 1;i<=n;i++){ all = 1; int vis[n+1] = {0}; vis[i] = 1; queue<int> q;q.push(i); int cnt = 0; while(!q.empty()){ int w = q.front();q.pop(); cnt++; for(auto j:v[w]){ if(vis[j]==0){ vis[j] = vis[w]+1; all += vis[j]; q.push(j); } } } if(cnt==n){ ans = min(ans,all); } } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...