#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
vector<int>G[MAXN];
long long U[MAXN], D[MAXN];
void dfs(int node, int papa) {
for (auto it:G[node])
if (it != papa) {
dfs(it, node);
U[node] += U[it];
D[node] += D[it];
}
}
struct Obj {
long long i, u, d;
bool operator <(const Obj& other) const {
bool ans;
if (u == 0) {
ans = 0;
} else {
if (other.u == 0) {
ans = 1;
} else {
if (1LL * d * other.u < 1LL * other.d * u)
ans = 1;
else
ans = 0;
}
}
return !ans;
}
};
long long scheduling_cost(vector<int>p, vector<int>u, vector<int>d) {
int n = p.size();
for (int i = 0; i < n; ++i)
U[i] = u[i], D[i] = d[i];
for (int i = 1; i < n; ++i)
G[p[i]].push_back(i);
dfs(0, -1);
long long ans = 0;
long long t = 0;
priority_queue<Obj>pq;
pq.push({0, U[0], D[0]});
while (!pq.empty()) {
Obj aux = pq.top();
pq.pop();
t += d[aux.i];
ans += t * u[aux.i];
for (auto it:G[aux.i])
pq.push({it, U[it], D[it]});
}
return ans;
}
/*int main() {
freopen("date.in", "r", stdin);
freopen("date.out", "w", stdout);
int n;
scanf("%d", &n);
vector<int>p(n), u(n), d(n);
for (int i = 0; i < n; ++i)
scanf("%d", &p[i]);
for (int i = 0; i < n; ++i)
scanf("%d", &u[i]);
for (int i = 0; i < n; ++i)
scanf("%d", &d[i]);
printf("%lld\n", scheduling_cost(p, u, d));
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
32 ms |
11640 KB |
Output is correct |
6 |
Correct |
61 ms |
18296 KB |
Output is correct |
7 |
Correct |
93 ms |
24952 KB |
Output is correct |
8 |
Correct |
121 ms |
31736 KB |
Output is correct |
9 |
Correct |
120 ms |
31608 KB |
Output is correct |
10 |
Correct |
119 ms |
31616 KB |
Output is correct |
11 |
Correct |
4 ms |
5120 KB |
Output is correct |
12 |
Correct |
119 ms |
31860 KB |
Output is correct |
13 |
Correct |
119 ms |
31608 KB |
Output is correct |
14 |
Correct |
119 ms |
31584 KB |
Output is correct |
15 |
Correct |
120 ms |
31608 KB |
Output is correct |
16 |
Correct |
118 ms |
31608 KB |
Output is correct |
17 |
Correct |
121 ms |
31608 KB |
Output is correct |
18 |
Correct |
120 ms |
31608 KB |
Output is correct |
19 |
Correct |
119 ms |
31608 KB |
Output is correct |
20 |
Correct |
125 ms |
31608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
176 ms |
20580 KB |
Output is correct |
5 |
Correct |
176 ms |
20580 KB |
Output is correct |
6 |
Correct |
174 ms |
20580 KB |
Output is correct |
7 |
Correct |
172 ms |
20580 KB |
Output is correct |
8 |
Correct |
171 ms |
20580 KB |
Output is correct |
9 |
Correct |
173 ms |
20580 KB |
Output is correct |
10 |
Correct |
172 ms |
20580 KB |
Output is correct |
11 |
Correct |
172 ms |
20580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
10 ms |
6000 KB |
Output is correct |
6 |
Correct |
178 ms |
20580 KB |
Output is correct |
7 |
Correct |
186 ms |
20580 KB |
Output is correct |
8 |
Correct |
203 ms |
20580 KB |
Output is correct |
9 |
Correct |
182 ms |
20592 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
4 ms |
5120 KB |
Output is correct |
12 |
Correct |
9 ms |
6000 KB |
Output is correct |
13 |
Correct |
10 ms |
6000 KB |
Output is correct |
14 |
Correct |
181 ms |
20580 KB |
Output is correct |
15 |
Correct |
188 ms |
20580 KB |
Output is correct |
16 |
Correct |
185 ms |
20584 KB |
Output is correct |
17 |
Correct |
180 ms |
20580 KB |
Output is correct |
18 |
Correct |
191 ms |
20580 KB |
Output is correct |
19 |
Correct |
180 ms |
20584 KB |
Output is correct |
20 |
Correct |
181 ms |
20580 KB |
Output is correct |
21 |
Correct |
182 ms |
20580 KB |
Output is correct |
22 |
Correct |
179 ms |
20580 KB |
Output is correct |
23 |
Correct |
178 ms |
20580 KB |
Output is correct |
24 |
Correct |
188 ms |
20580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
32 ms |
11640 KB |
Output is correct |
6 |
Correct |
61 ms |
18296 KB |
Output is correct |
7 |
Correct |
93 ms |
24952 KB |
Output is correct |
8 |
Correct |
121 ms |
31736 KB |
Output is correct |
9 |
Correct |
120 ms |
31608 KB |
Output is correct |
10 |
Correct |
119 ms |
31616 KB |
Output is correct |
11 |
Correct |
4 ms |
5120 KB |
Output is correct |
12 |
Correct |
119 ms |
31860 KB |
Output is correct |
13 |
Correct |
119 ms |
31608 KB |
Output is correct |
14 |
Correct |
119 ms |
31584 KB |
Output is correct |
15 |
Correct |
120 ms |
31608 KB |
Output is correct |
16 |
Correct |
118 ms |
31608 KB |
Output is correct |
17 |
Correct |
121 ms |
31608 KB |
Output is correct |
18 |
Correct |
120 ms |
31608 KB |
Output is correct |
19 |
Correct |
119 ms |
31608 KB |
Output is correct |
20 |
Correct |
125 ms |
31608 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
22 |
Correct |
4 ms |
4992 KB |
Output is correct |
23 |
Correct |
4 ms |
4992 KB |
Output is correct |
24 |
Correct |
176 ms |
20580 KB |
Output is correct |
25 |
Correct |
176 ms |
20580 KB |
Output is correct |
26 |
Correct |
174 ms |
20580 KB |
Output is correct |
27 |
Correct |
172 ms |
20580 KB |
Output is correct |
28 |
Correct |
171 ms |
20580 KB |
Output is correct |
29 |
Correct |
173 ms |
20580 KB |
Output is correct |
30 |
Correct |
172 ms |
20580 KB |
Output is correct |
31 |
Correct |
172 ms |
20580 KB |
Output is correct |
32 |
Correct |
4 ms |
4992 KB |
Output is correct |
33 |
Correct |
3 ms |
4992 KB |
Output is correct |
34 |
Correct |
3 ms |
4992 KB |
Output is correct |
35 |
Correct |
4 ms |
5120 KB |
Output is correct |
36 |
Correct |
10 ms |
6000 KB |
Output is correct |
37 |
Correct |
178 ms |
20580 KB |
Output is correct |
38 |
Correct |
186 ms |
20580 KB |
Output is correct |
39 |
Correct |
203 ms |
20580 KB |
Output is correct |
40 |
Correct |
182 ms |
20592 KB |
Output is correct |
41 |
Correct |
4 ms |
4992 KB |
Output is correct |
42 |
Correct |
4 ms |
5120 KB |
Output is correct |
43 |
Correct |
9 ms |
6000 KB |
Output is correct |
44 |
Correct |
10 ms |
6000 KB |
Output is correct |
45 |
Correct |
181 ms |
20580 KB |
Output is correct |
46 |
Correct |
188 ms |
20580 KB |
Output is correct |
47 |
Correct |
185 ms |
20584 KB |
Output is correct |
48 |
Correct |
180 ms |
20580 KB |
Output is correct |
49 |
Correct |
191 ms |
20580 KB |
Output is correct |
50 |
Correct |
180 ms |
20584 KB |
Output is correct |
51 |
Correct |
181 ms |
20580 KB |
Output is correct |
52 |
Correct |
182 ms |
20580 KB |
Output is correct |
53 |
Correct |
179 ms |
20580 KB |
Output is correct |
54 |
Correct |
178 ms |
20580 KB |
Output is correct |
55 |
Correct |
188 ms |
20580 KB |
Output is correct |
56 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |