Submission #723786

#TimeUsernameProblemLanguageResultExecution timeMemory
723786rshohruhBosses (BOI16_bosses)C++14
100 / 100
1486 ms940 KiB
#include <bits/stdc++.h> using namespace std; #define int long long vector<vector<int>> dp1, dp2; vector<bool> vis; pair<int, int> dfs(int u){ vis[u] = true; pair<int, int> res0 = {1, 0}, res1; for(int v : dp2[u]){ res1 = dfs(v); res0.second += res1.second; res0.first += res1.first; } res0.second += res0.first; return res0; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; dp1.resize(n); for(int i=0; i<n; ++i){ int k; cin >> k; for(int j=0; j<k; ++j){ int x; cin >> x; dp1[x-1].push_back(i); } } int ans = 1e18; for(int u=0; u<n; ++u){ vis.assign(n, false); dp2.assign(n, {}); queue<int> q; q.push(u); vis[u] = true; while(!q.empty()){ int u = q.front(); q.pop(); for(int v : dp1[u]){ if(!vis[v]){ vis[v] = true; q.emplace(v); dp2[u].push_back(v); } } } bool f = true; for(int i=0; i<n; ++i) if(!vis[i]){ f = false; } if(f) ans = min(ans, dfs(u).second); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...