# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
857990 |
2023-10-07T08:54:18 Z |
vjudge1 |
Bosses (BOI16_bosses) |
C++17 |
|
1 ms |
348 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
const int maxn = 5e3 + 5;
bool mark[maxn];
int cnt[maxn], H_cnt[maxn], n;
vector<pii > P_pars;
int calc(int root) {
vector<int> height[maxn];
memset(H_cnt, 0, sizeof H_cnt);
memset(mark, false, sizeof mark);
height[0].pb(root);
H_cnt[0] = 1;
mark[root] = true;
ll sum = n, dec = 1;
for (int i = 1; i < n; i++) {
for (int x: height[i - 1]) {
for (pii u: P_pars) {
int v = u.first, par = u.second;
if (par == x and v != x and !mark[v]) {
height[i].pb(v);
H_cnt[i]++;
mark[v] = true;
}
}
}
sum += n - dec;
dec += H_cnt[i];
}
return sum;
}
inline int minn(ll a, ll b) {
if(a <= b)
return a;
return b;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int mx = 0;
vector<int> roots;
cin >> n;
for (int i = 1; i <= n; i++) {
int c;
cin >> c;
for (int j = 1; j <= c; j++) {
int x;
cin >> x;
P_pars.pb({i, x});
cnt[x]++;
if (cnt[x] == mx) {
roots.pb(x);
} else if (cnt[x] > mx) {
mx = cnt[x];
roots.clear();
roots.pb(x);
}
}
}
ll ans = 1e18;
for (int r: roots) {
ans = minn(ans, calc(r));
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |