Submission #531856

#TimeUsernameProblemLanguageResultExecution timeMemory
531856makanhuliaBosses (BOI16_bosses)C++17
100 / 100
850 ms696 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll signed main(){ cin.tie(0) -> ios_base::sync_with_stdio(0); int n; cin >> n; vector<vector<int>> adj(n, vector<int>()); // int r = -1; for(int i=0;i<n;i++) { int k; cin >> k; // if(k == 0) r = i; for(int j=0;j<k;j++) { int x; cin >> x; x--; adj[x].push_back(i); } } // if(r == -1) // { // int mx = 0; // for(int i=0;i<n;i++) // { // if(adj[i].size() > mx) // { // mx = adj[i].size(); // r = i; // } // } // } int ans = LLONG_MAX; for(int r=0;r<n;r++) { queue<int> q; q.push(r); int cnt = 1; vector<bool> vis(n); vector<int> d(n); d[r] = 1; vis[r] = 1; while(!q.empty()){ int u = q.front(); q.pop(); for(auto i : adj[u]) { if(!vis[i]) { vis[i] = 1; d[i] = d[u] + 1; q.push(i); cnt++; } } } bool ok = 1; int sm = 0; for(int i=0;i<n;i++) { sm += d[i]; ok &= (d[i] > 0); } if(ok) ans = min(ans, sm); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...