Submission #374025

#TimeUsernameProblemLanguageResultExecution timeMemory
374025ritul_kr_singhBosses (BOI16_bosses)C++17
0 / 100
1 ms384 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>> g; vector<bool> vis; pair<int, int> dfs(int u){ vis[u] = true; pair<int, int> res0 = {1, 0}, res1; for(int v : g[u]){ if(!vis[v]){ 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; g.resize(n); for(int i=0; i<n; ++i){ int k; cin >> k; for(int j=0; j<k; ++j){ int x; cin >> x; g[x-1].push_back(i); } } int ans = 1e18; for(int root=0; root<n; ++root){ vis.assign(n, false); pair<int, int> res = dfs(root); for(int i=0; i<n; ++i) if(!vis[i]) continue; ans = min(ans, res.second); } cout << ans nl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...