Submission #374047

#TimeUsernameProblemLanguageResultExecution timeMemory
374047ritul_kr_singhBosses (BOI16_bosses)C++17
100 / 100
1453 ms1132 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; } vector<int> order; order.push_back(root); vis[root] = true; bool ok = true; for(int i=0; i<n; ++i){ if(i==(int)order.size()){ ok = false; break; } int u = order[i]; for(int v : g0[u]){ if(!vis[v]){ vis[v] = true; order.push_back(v); g1[u].push_back(v); } } } if(!ok) continue; reverse(order.begin(), order.end()); for(int i : order){ for(int j : g1[i]){ curr[i] += curr[j]; } } 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...