Submission #98868

#TimeUsernameProblemLanguageResultExecution timeMemory
98868robot_dreamsBosses (BOI16_bosses)C++17
67 / 100
1549 ms1204 KiB
#include <bits/stdc++.h> #define F first #define S second #define forn(i, n) for (int i = 0; i < int(n); i++) using namespace std; using ll = long long; using pll = pair<ll, ll>; bool all(vector<bool>& bs) { for (bool b : bs) if (!b) return false; return true; } pll dfs(vector<vector<int>>& tree, int v) { ll child_sum = 0, subtree_sum = 0; for (int w : tree[v]) { pll p = dfs(tree, w); child_sum += p.F; subtree_sum += p.S; } ll salary = child_sum + 1; return {salary, subtree_sum + salary}; } int main() { ios_base::sync_with_stdio(false); cout << setprecision(12); cin.tie(nullptr); int n; cin >> n; vector<vector<int>> adj(n); forn(v, n) { int k; cin >> k; forn(i, k) { int u; cin >> u; u--; adj[u].push_back(v); } } ll ans = LLONG_MAX; forn(root, n) { queue<int> q; vector<bool> visited(n); vector<vector<int>> tree(n); q.push(root); visited[root] = true; while (!q.empty()) { int v = q.front(); q.pop(); for (int w : adj[v]) { if (visited[w]) continue; tree[v].push_back(w); q.push(w); visited[w] = true; } } if (all(visited)) ans = min(ans, dfs(tree, root).S); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...