#include "job.h"
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
#define ll long long
struct job{
int u, d, id;
bool operator < (const job &rhs) const{
return d * 1ll * rhs.u > u * 1ll * rhs.d;
}
};
vector<int> adj[200005];
long long scheduling_cost(vector<int> p, vector<int> u, vector<int> d){
int n = p.size();
for(int i = 1; i < n; i ++)
adj[p[i]].push_back(i);
priority_queue<job> pq;
pq.push({u[0], d[0], 0});
ll ans = 0ll, tim = 0ll;
for(; pq.size();){
auto nw = pq.top(); pq.pop();
tim += d[nw.id]; ans += tim * 1ll * u[nw.id];
for(int nx : adj[nw.id])
pq.push({u[nx], d[nx], nx});
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
23 ms |
8376 KB |
Output is correct |
6 |
Correct |
42 ms |
11916 KB |
Output is correct |
7 |
Correct |
62 ms |
15548 KB |
Output is correct |
8 |
Correct |
101 ms |
19080 KB |
Output is correct |
9 |
Correct |
82 ms |
19116 KB |
Output is correct |
10 |
Correct |
83 ms |
19036 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
83 ms |
19080 KB |
Output is correct |
13 |
Correct |
84 ms |
19068 KB |
Output is correct |
14 |
Correct |
82 ms |
19072 KB |
Output is correct |
15 |
Correct |
85 ms |
19092 KB |
Output is correct |
16 |
Correct |
82 ms |
19016 KB |
Output is correct |
17 |
Correct |
83 ms |
19080 KB |
Output is correct |
18 |
Correct |
83 ms |
19100 KB |
Output is correct |
19 |
Correct |
87 ms |
19080 KB |
Output is correct |
20 |
Correct |
83 ms |
19080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
130 ms |
15984 KB |
Output is correct |
5 |
Correct |
129 ms |
15988 KB |
Output is correct |
6 |
Correct |
126 ms |
16008 KB |
Output is correct |
7 |
Correct |
131 ms |
15964 KB |
Output is correct |
8 |
Correct |
123 ms |
16016 KB |
Output is correct |
9 |
Correct |
141 ms |
15976 KB |
Output is correct |
10 |
Correct |
126 ms |
15968 KB |
Output is correct |
11 |
Correct |
124 ms |
15996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
9 ms |
5528 KB |
Output is correct |
6 |
Correct |
130 ms |
14216 KB |
Output is correct |
7 |
Correct |
128 ms |
16624 KB |
Output is correct |
8 |
Correct |
129 ms |
16640 KB |
Output is correct |
9 |
Correct |
130 ms |
16620 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
5068 KB |
Output is correct |
12 |
Correct |
7 ms |
5580 KB |
Output is correct |
13 |
Correct |
8 ms |
5692 KB |
Output is correct |
14 |
Correct |
131 ms |
16620 KB |
Output is correct |
15 |
Correct |
134 ms |
16624 KB |
Output is correct |
16 |
Correct |
130 ms |
16564 KB |
Output is correct |
17 |
Correct |
130 ms |
16616 KB |
Output is correct |
18 |
Correct |
136 ms |
16620 KB |
Output is correct |
19 |
Correct |
138 ms |
16612 KB |
Output is correct |
20 |
Correct |
128 ms |
16624 KB |
Output is correct |
21 |
Correct |
153 ms |
16616 KB |
Output is correct |
22 |
Correct |
152 ms |
16560 KB |
Output is correct |
23 |
Correct |
149 ms |
16612 KB |
Output is correct |
24 |
Correct |
148 ms |
16564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Incorrect |
120 ms |
19204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
23 ms |
8376 KB |
Output is correct |
6 |
Correct |
42 ms |
11916 KB |
Output is correct |
7 |
Correct |
62 ms |
15548 KB |
Output is correct |
8 |
Correct |
101 ms |
19080 KB |
Output is correct |
9 |
Correct |
82 ms |
19116 KB |
Output is correct |
10 |
Correct |
83 ms |
19036 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
83 ms |
19080 KB |
Output is correct |
13 |
Correct |
84 ms |
19068 KB |
Output is correct |
14 |
Correct |
82 ms |
19072 KB |
Output is correct |
15 |
Correct |
85 ms |
19092 KB |
Output is correct |
16 |
Correct |
82 ms |
19016 KB |
Output is correct |
17 |
Correct |
83 ms |
19080 KB |
Output is correct |
18 |
Correct |
83 ms |
19100 KB |
Output is correct |
19 |
Correct |
87 ms |
19080 KB |
Output is correct |
20 |
Correct |
83 ms |
19080 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
3 ms |
4940 KB |
Output is correct |
23 |
Correct |
3 ms |
4940 KB |
Output is correct |
24 |
Correct |
130 ms |
15984 KB |
Output is correct |
25 |
Correct |
129 ms |
15988 KB |
Output is correct |
26 |
Correct |
126 ms |
16008 KB |
Output is correct |
27 |
Correct |
131 ms |
15964 KB |
Output is correct |
28 |
Correct |
123 ms |
16016 KB |
Output is correct |
29 |
Correct |
141 ms |
15976 KB |
Output is correct |
30 |
Correct |
126 ms |
15968 KB |
Output is correct |
31 |
Correct |
124 ms |
15996 KB |
Output is correct |
32 |
Correct |
3 ms |
4940 KB |
Output is correct |
33 |
Correct |
3 ms |
4940 KB |
Output is correct |
34 |
Correct |
3 ms |
4940 KB |
Output is correct |
35 |
Correct |
3 ms |
4940 KB |
Output is correct |
36 |
Correct |
9 ms |
5528 KB |
Output is correct |
37 |
Correct |
130 ms |
14216 KB |
Output is correct |
38 |
Correct |
128 ms |
16624 KB |
Output is correct |
39 |
Correct |
129 ms |
16640 KB |
Output is correct |
40 |
Correct |
130 ms |
16620 KB |
Output is correct |
41 |
Correct |
3 ms |
4940 KB |
Output is correct |
42 |
Correct |
4 ms |
5068 KB |
Output is correct |
43 |
Correct |
7 ms |
5580 KB |
Output is correct |
44 |
Correct |
8 ms |
5692 KB |
Output is correct |
45 |
Correct |
131 ms |
16620 KB |
Output is correct |
46 |
Correct |
134 ms |
16624 KB |
Output is correct |
47 |
Correct |
130 ms |
16564 KB |
Output is correct |
48 |
Correct |
130 ms |
16616 KB |
Output is correct |
49 |
Correct |
136 ms |
16620 KB |
Output is correct |
50 |
Correct |
138 ms |
16612 KB |
Output is correct |
51 |
Correct |
128 ms |
16624 KB |
Output is correct |
52 |
Correct |
153 ms |
16616 KB |
Output is correct |
53 |
Correct |
152 ms |
16560 KB |
Output is correct |
54 |
Correct |
149 ms |
16612 KB |
Output is correct |
55 |
Correct |
148 ms |
16564 KB |
Output is correct |
56 |
Correct |
3 ms |
4940 KB |
Output is correct |
57 |
Incorrect |
120 ms |
19204 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |