Submission #884329

#TimeUsernameProblemLanguageResultExecution timeMemory
884329vjudge1Bosses (BOI16_bosses)C++17
100 / 100
899 ms1044 KiB
#include <bits/stdc++.h> #define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #define fast_io ios::sync_with_stdio(false);cin.tie(0); #define what(x) cerr << #x << " is " << x << '\n'; #define kill(x) {cout << x << '\n'; return 0;} #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define pb push_back #define ll long long #define F first #define S second const ll inf = 1e18, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621; using namespace std; #define int ll const ll N = 5e3 + 10, LG = 20; vector<int> adj[N]; vector<int> G[N]; bitset<N> mark; int dp[N]; void dfs (int v) { dp[v] = 1; for (auto u: G[v]) { dfs(u); dp[v] += dp[u]; } } int32_t main() { fast_io; int n, ans = inf; cin >> n; for (int i = 1; i <= n; i++) { int k, x; cin >> k; while (k--) { cin >> x; adj[x].pb(i); } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) G[j].clear(); queue<int> q; mark.reset(); q.push(i); mark[i] = true; while (q.size()) { int v = q.front(); q.pop(); for (auto u: adj[v]) { if (!mark[u]) { q.push(u); mark[u] = true; G[v].pb(u); } } } memset(dp, 0, sizeof dp); dfs(i); int sum = 0; for (int j = 1; j <= n; j++) { sum += dp[j]; if (dp[j] == 0) goto Hell; } ans = min(ans, sum); Hell:; } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...