Submission #374033

#TimeUsernameProblemLanguageResultExecution timeMemory
374033ritul_kr_singhBosses (BOI16_bosses)C++17
67 / 100
1594 ms1036 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; pair<int, int> dfs(int u){ vis[u] = true; pair<int, int> res0 = {1, 0}, res1; for(int v : g1[u]){ res1 = dfs(v); res0.second += res1.second; res0.first += res1.first; } res0.second += res0.first; return res0; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; g0.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 ans = 1e18; for(int root=0; root<n; ++root){ vis.assign(n, false); g1.assign(n, {}); queue<int> q; q.push(root); vis[root] = true; while(!q.empty()){ int u = q.front(); q.pop(); for(int v : g0[u]){ if(!vis[v]){ vis[v] = true; q.emplace(v); g1[u].push_back(v); } } } bool ok = true; for(int i=0; i<n; ++i) if(!vis[i]){ ok = false; } if(ok) ans = min(ans, dfs(root).second); } cout << ans nl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...