Submission #1014336

#TimeUsernameProblemLanguageResultExecution timeMemory
1014336aufanBosses (BOI16_bosses)C++17
67 / 100
1541 ms1360 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second using namespace std; const int inff = 1e18; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<vector<int>> v(n + 1); for (int i = 1; i <= n; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int x; cin >> x; v[x].push_back(i); } } int ans = inff; for (int i = 1; i <= n; i++) { vector<int> d(n + 1, -1), q(1, i); vector<vector<int>> g(n + 1); d[i] = 0; for (int j = 0; j < (int)q.size(); j++) { int x = q[j]; for (auto z : v[x]) { if (d[z] == -1) { d[z] = d[x] + 1; g[x].push_back(z); q.push_back(z); } } } if ((int)q.size() < n) continue; int res = 0; vector<int> val(n + 1); for (int j = n - 1; j >= 0; j--) { int x = q[j]; val[x] = 1; for (auto z : g[x]) { val[x] += val[z]; } res += val[x]; } ans = min(ans, res); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...