Submission #397164

#TimeUsernameProblemLanguageResultExecution timeMemory
397164giorgikobBosses (BOI16_bosses)C++14
100 / 100
844 ms24032 KiB
#include<bits/stdc++.h> #define ll long long #define ff first #define ss second #define pb push_back using namespace std; const int N = 1e6+50, mod = 1e9+7, K = 31; int n,k,x; ll answer,res; vector<int>gr[N]; bool fix[N]; int cnt = 0; void bfs(int x){ queue<pair<int,int>>q; q.push({x,1}); fix[x] = 1; while(q.size()){ auto p = q.front(); q.pop(); int x = p.ff; int h = p.ss; cnt++; res += h; for(auto to : gr[x]){ if(fix[to]) continue; q.push({to,h+1}); fix[to] = 1; } } } inline void test_case(){ cin >> n; for(int i = 1; i <= n; i++){ cin >> k; for(int j = 1; j <= k; j++){ cin >> x; //v[i].pb(x); gr[x].pb(i); } } ll answer = 1e18; for(int i = 1; i <= n; i++){ bfs(i); if(cnt == n)answer = min(answer, res); res = 0; cnt = 0; for(int j = 1; j <= n; j++) fix[j] = 0; } cout << answer << endl; } main(){ ios::sync_with_stdio(0); int T = 1; //cin >> T; for(int i = 1; i <= T; i++){ test_case(); } }

Compilation message (stderr)

bosses.cpp:59:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 |  main(){
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...