Submission #884345

#TimeUsernameProblemLanguageResultExecution timeMemory
884345vjudge1Bosses (BOI16_bosses)C++17
0 / 100
1 ms360 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pll array<ll, 2> const int N = 5e3 + 4; const ll INF = 1ll << 62; int n; bool vis[N]; vector<int> in[N]; pll dfs(int v) { vis[v] = true; pll ret = {0, 0}; for (int u : in[v]) { if (vis[u] == false) { pll res = dfs(u); ret[0] += res[0]; ret[1] += res[1]; } } ++ret[0]; ret[1] += ret[0]; return ret; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) { int k; cin >> k; while (k--) { int v; cin >> v; --v; in[v].pb(i); } } ll ans = INF; for (int i = 0; i < n; ++i) { pll res = dfs(i); bool seeAll = true; for (int j = 0; j < n; ++j) { seeAll &= vis[j]; vis[j] = false; } if (seeAll == true) { ans = min(ans, res[1]); } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...