Submission #239231

#TimeUsernameProblemLanguageResultExecution timeMemory
239231aggu_01000101Bosses (BOI16_bosses)C++14
100 / 100
820 ms728 KiB
#include <bits/stdc++.h> #define int long long #define INF 1000000000000000 #define lchild(i) (i*2 + 1) #define rchild(i) (i*2 + 2) #define mid(l, u) ((l+u)/2) #define x(p) p.first #define y(p) p.second #define MOD 998244353 using namespace std; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; vector<int> children[n]; for(int i =0 ;i<n;i++){ int k; cin>>k; while(k--){ int par; cin>>par; children[par-1].push_back(i); } } int ans = INF; for(int i = 0;i<n;i++){ bool chosen[n]; for(int j = 0;j<n;j++) chosen[j] = false; chosen[i] = true; queue<pair<int, int>> q; q.push({i, 0}); int cnt = 1; int cost = 0; while(!q.empty()){ pair<int, int> curr = q.front(); cost+=(curr.second + 1); q.pop(); for(int j: children[curr.first]){ if(chosen[j]) continue; cnt++; chosen[j] = true; q.push({j, curr.second+1}); } } if(cnt!=n) continue; ans = min(ans, cost); } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...