Submission #723479

#TimeUsernameProblemLanguageResultExecution timeMemory
723479baneBosses (BOI16_bosses)C++17
100 / 100
1283 ms1008 KiB
#include<bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int>g[n]; for (int i = 0 ; i < n; i++){ int k; cin >> k; while(k--){ int x; cin >> x; --x; g[x].emplace_back(i); } } int visited[n]; vector<int>adj[n]; int ans = (int)1e9; for (int i = 0; i < n; i++){ queue<int>q; q.push(i); for (int j = 0; j < n; j++){ visited[j] = 0; adj[j].clear(); } int cnt = 0; while(!q.empty()){ int node = q.front(); q.pop(); ++cnt; visited[node] = 1; for (auto p : g[node]){ if(!visited[p]){ visited[p] = 1; q.push(p); adj[node].emplace_back(p); } } } if (cnt < n)continue; function<pair<int,int>(int,int)>dfs = [&](int u, int p){ int sum = 1; int tot = 0; for (int& x : adj[u]){ if (x == p)continue; auto m = dfs(x,u); sum+=m.first; tot+=m.second; } tot+=sum; return make_pair(sum, tot); }; ans = min(ans,dfs(i,-1).second); } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...