# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1014336 |
2024-07-04T16:53:19 Z |
aufan |
Bosses (BOI16_bosses) |
C++17 |
|
1500 ms |
1360 KB |
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int inff = 1e18;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<vector<int>> v(n + 1);
for (int i = 1; i <= n; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int x;
cin >> x;
v[x].push_back(i);
}
}
int ans = inff;
for (int i = 1; i <= n; i++) {
vector<int> d(n + 1, -1), q(1, i);
vector<vector<int>> g(n + 1);
d[i] = 0;
for (int j = 0; j < (int)q.size(); j++) {
int x = q[j];
for (auto z : v[x]) {
if (d[z] == -1) {
d[z] = d[x] + 1;
g[x].push_back(z);
q.push_back(z);
}
}
}
if ((int)q.size() < n) continue;
int res = 0;
vector<int> val(n + 1);
for (int j = n - 1; j >= 0; j--) {
int x = q[j];
val[x] = 1;
for (auto z : g[x]) {
val[x] += val[z];
}
res += val[x];
}
ans = min(ans, res);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
456 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
456 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
386 ms |
924 KB |
Output is correct |
15 |
Correct |
41 ms |
860 KB |
Output is correct |
16 |
Correct |
1248 ms |
1360 KB |
Output is correct |
17 |
Execution timed out |
1541 ms |
1248 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |