Submission #790740

#TimeUsernameProblemLanguageResultExecution timeMemory
790740christinelynnBosses (BOI16_bosses)C++17
100 / 100
428 ms5324 KiB
#include<bits/stdc++.h> #define pb push_back #define int long long #define INF 1e18 #define endl '\n' using namespace std; int n , k , ans = 1e18 , dist[200005]; vector < int > adj[200005]; bool vis[200005]; void bfs(int s){ queue < int > q; vis[s] = true; q.push(s); dist[s] = 1; int ttl = 1; while(!q.empty()){ int u = q.front(); q.pop(); for(int i : adj[u]){ if(!vis[i]){ vis[i] = true; q.push(i); dist[i] = dist[u] + 1; ttl += dist[i]; } } } bool bs = true; for(int i = 1 ; i <= n ; i++) if(!vis[i]) bs = false; if(bs) ans = min(ans , ttl); } signed main(){ cin >> n; for(int i = 1 ; i <= n ; i++){ cin >> k; for(int j = 1 ; j <= k ; j++){ int tmp; cin >> tmp; adj[tmp].pb(i); } } for(int i = 1 ; i <= n ; i++){ for(int j = 1 ; j <= n ; j++){ vis[j] = false; dist[j] = 0; } bfs(i); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...