# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
857772 | qrno | Bosses (BOI16_bosses) | C++11 | 411 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 <queue>
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<int>, MAXN> G;
array<int, MAXN> val, last;
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++) {
queue<int> Q;
Q.push(i);
val[i] = 1;
last[i] = i;
int done = 0, sum = 0;
while (!Q.empty()) {
auto v = Q.front(); Q.pop();
sum += val[v];
done++;
for (auto u : G[v]) {
if (last[u] != i) {
Q.push(u);
val[u] = val[v]+1;
last[u] = i;
}
}
}
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... |