Submission #1171941

#TimeUsernameProblemLanguageResultExecution timeMemory
1171941JahonaliXBosses (BOI16_bosses)C++20
67 / 100
1596 ms1004 KiB
#include <bits/stdc++.h> using namespace std; int main() { #ifdef JahonaliX freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, z = INT_MAX; cin >> n; vector<vector<int>> a(n); for (int i = 0; i < n; ++i) { int k; cin >> k; while (k--) { int x; cin >> x; x--; a[x].emplace_back(i); } } for (int i = 0; i < n; ++i) { vector<vector<int>> b(n); vector<bool> v(n); v[i] = true; queue<int> q; q.emplace(i); while (!q.empty()) { int x = q.front(); q.pop(); for (int j : a[x]) { if (v[j]) continue; q.emplace(j); v[j] = true; b[x].emplace_back(j); } } bool ok = true; for (int j = 0; j < n; ++j) ok &= v[j]; if (ok) { vector<int> x(n, 1); function<int(int)> dfs = [&] (int i) -> int { for (int j : b[i]) x[i] += dfs(j); return x[i]; }; dfs(i); z = min(z, accumulate(x.begin(), x.end(), 0)); } } cout << z; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...