Submission #520687

#TimeUsernameProblemLanguageResultExecution timeMemory
520687Alex_tz307Bosses (BOI16_bosses)C++17
0 / 100
1 ms428 KiB
#include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; const int kN = 5e3; vector<int> t[1 + kN]; int sum; int dfs(int u, int par) { int salary = 1; for (int v : t[u]) { if (v != par) { salary += dfs(v, u); } } sum += salary; return salary; } void minSelf(int &x, int y) { if (y < x) { x = y; } } void testCase() { int n; cin >> n; vector<vector<int>> g(n + 1); for (int v = 1; v <= n; ++v) { int k; cin >> k; for (int i = 0; i < k; ++i) { int u; cin >> u; g[u].emplace_back(v); } } int ans = INF; for (int root = 1; root <= n; ++root) { for (int v = 1; v <= n; ++v) { t[v].clear(); } queue<int> q; q.emplace(root); vector<bool> vis(n + 1); vis[root] = true; while (!q.empty()) { int u = q.front(); q.pop(); for (int v : g[u]) { if (!vis[v]) { t[u].emplace_back(v); q.emplace(v); vis[v] = true; } } } sum = 0; dfs(root, 0); minSelf(ans, sum); } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int tests = 1; for (int tc = 0; tc < tests; ++tc) { testCase(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...