제출 #520689

#제출 시각아이디문제언어결과실행 시간메모리
520689Alex_tz307Bosses (BOI16_bosses)C++17
100 / 100
1334 ms872 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 salary = 1; for (int v : t[u]) { salary += dfs(v); } 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<int> vis(n + 1); vis[root] = 1; 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] = 1; } } } if (accumulate(vis.begin() + 1, vis.end(), 0) == n) { sum = 0; dfs(root); 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...