# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
857776 | qrno | Bosses (BOI16_bosses) | C++17 | 356 ms | 848 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 <cstdio>
#include <vector>
#include <array>
#include <bitset>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const int INF = 1e9;
const int MAXN = 5e3;
int best = INF;
int N;
array<vector<short>, MAXN> G;
array<short, MAXN> val, q;
signed main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) {
int K; scanf("%d", &K);
while (K--) {
int u; scanf("%d", &u); u--;
G[u].push_back(i);
}
}
for (int i = 0; i < N; i++) {
int l = 0, r = -1;
bitset<MAXN> vis;
q[++r] = i;
val[i] = 1;
vis[i] = true;
int done = 0, sum = 0;
while (l <= r) {
auto v = q[l++];
sum += val[v];
done++;
for (auto u : G[v]) {
if (!vis[u]) {
q[++r] = u;
val[u] = val[v]+1;
vis[u] = true;
}
}
}
if (done < N) continue;
best = min(best, sum);
}
printf("%d", best);
}
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... |