Submission #884318

#TimeUsernameProblemLanguageResultExecution timeMemory
884318vjudge1Bosses (BOI16_bosses)C++17
0 / 100
1 ms604 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; 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]; } } int main() { fast_io; int n, ans = INT_MAX; 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); } } } dfs(i); int sum = 0; for (int i = 1; i <= n; i++) sum += dp[i]; ans = min(ans, sum); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...