Submission #329763

#TimeUsernameProblemLanguageResultExecution timeMemory
329763SuhaibSawalha1Bosses (BOI16_bosses)C++17
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj; int vid = 1, vis, cost; vector<int> visited; int dfs (int u){ visited[u] = vid; ++vis; int sum = 1; for (int v : adj[u]){ if (visited[v] ^ vid){ sum += dfs(v); } } cost += sum; return sum; } int main (){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; adj.resize(n); for (int u = 0; u < n; ++u){ int k, v; cin >> k; while (k--){ cin >> v; adj[--v].push_back(u); } } visited.resize(n); int ans = 1e9; for (int i = 0; i < n; ++i, ++vid, vis = cost = 0){ dfs(i); if (vis == n){ ans = min(ans, cost); } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...