Submission #374046

#TimeUsernameProblemLanguageResultExecution timeMemory
374046ritul_kr_singhBosses (BOI16_bosses)C++17
67 / 100
1584 ms1428 KiB
//#pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long #define sp << " " << #define nl << "\n" vector<vector<int>> g0, g1; vector<bool> vis; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; g0.resize(n); g1.resize(n); vis.resize(n); for(int i=0; i<n; ++i){ int k; cin >> k; for(int j=0; j<k; ++j){ int x; cin >> x; g0[x-1].push_back(i); } } int curr[n]; int ans = 1e18; for(int root=0; root<n; ++root){ for(int i=0; i<n; ++i){ vis[i] = false; g1[i].clear(); curr[i] = 1; } queue<int> q; q.push(root); vector<int> order; vis[root] = true; while(!q.empty()){ int u = q.front(); q.pop(); order.push_back(u); for(int v : g0[u]){ if(!vis[v]){ vis[v] = true; q.emplace(v); g1[u].push_back(v); } } } reverse(order.begin(), order.end()); for(int i : order){ for(int j : g1[i]){ curr[i] += curr[j]; } } bool ok = true; for(int i=0; i<n; ++i){ if(!vis[i]) ok = false; } if(!ok) continue; ans = min(ans, accumulate(curr, curr+n, 0LL)); } cout << ans nl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...