# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
857767 |
2023-10-06T22:06:38 Z |
qrno |
Bosses (BOI16_bosses) |
C++17 |
|
423 ms |
748 KB |
#include <bits/stdc++.h>
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() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> N;
for (int i = 0; i < N; i++) {
int K; cin >> K;
while (K--) {
int u; cin >> 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];
if (sum >= best) break;
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);
}
cout << best << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
73 ms |
664 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
423 ms |
728 KB |
Output is correct |
17 |
Correct |
115 ms |
604 KB |
Output is correct |
18 |
Correct |
103 ms |
748 KB |
Output is correct |