Submission #784116

#TimeUsernameProblemLanguageResultExecution timeMemory
784116KindaNamelessBosses (BOI16_bosses)C++14
100 / 100
392 ms716 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define fi first #define se second #define pb push_back #define mp make_pair #define all(a) a.begin(), a.end() vector<int> adj[5001]; bool vis[5001]; int n, val, answer = 2e9; void bfs(int cur){ queue<pair<int, int>> q; vis[cur] = 1; q.push({cur, 1}); int cnt = 0; while(!q.empty()){ pair<int, int> now = q.front(); q.pop(); cnt++; val += now.second; for(int nx : adj[now.first]){ if(!vis[nx]){ vis[nx] = 1; q.push({nx, now.second + 1}); } } } if(cnt < n)val = 2e9; } void solve(){ cin >> n; for(int i = 1; i <= n; ++i){ int k; cin >> k; for(int j = 1; j <= k; ++j){ int x; cin >> x; adj[x].push_back(i); } } for(int i = 1; i <= n; ++i){ fill(vis, vis + n + 1, 0); val = 0; bfs(i); answer = min(answer, val); } cout << answer; return; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; //cin >> tc; while(tc--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...