# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
231519 | Haunted_Cpp | Bosses (BOI16_bosses) | C++17 | 1519 ms | 888 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
vector< vector<int> > g (N);
int p [N];
bitset<N> vis;
int subtree [N];
int dfs (int node) {
int sum = 0;
subtree[node] = 1;
int res = 0;
for (auto to : g[node]) {
if (p[to] == node) {
res += dfs (to);
sum += subtree[to];
}
}
subtree[node] += sum;
return res + subtree[node];
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int st;
cin >> st;
--st;
g[st].emplace_back(i);
}
}
int mn = 1e9;
for (int i = 0; i < n; i++) {
vis.reset ();
vis[i] = 1;
p[i] = -1;
queue<int> q;
q.push(i);
while (!q.empty()) {
int node = q.front();
q.pop();
for (auto to : g[node]) {
if (!vis[to]) {
vis[to] = 1;
p[to] = node;
q.push(to);
}
}
}
if (vis.count() != n) continue;
vis.reset ();
mn = min (mn, dfs (i));
}
cout << mn << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |