#include "job.h"
#include <vector>
#include<set>
#include<iostream>
#define LL long long
#define MAXN 300005
using namespace std;
struct Job {LL wt, t;};
class CompareClass {
public:
bool operator() (Job a, Job b) {
return(a.wt*b.t > a.t*b.wt); //wt, time
}
};
int N, big[MAXN];
LL U[MAXN], D[MAXN], ans; //cost, time
vector<int> chd[MAXN];
multiset<Job, CompareClass> Order[MAXN];
void dfs(int u) {
big[u]=u;
for (auto v: chd[u]) {
dfs(v);
if (Order[big[v]].size() > Order[big[u]].size()) {swap(big[u], big[v]);}
for (Job j: Order[big[v]]) {
Order[big[u]].insert(j);
}
}
while (Order[big[u]].size()) {
Job f = *Order[big[u]].begin();
if (f.wt*D[u] >= f.t*U[u]) {
ans-=f.t*U[u];
U[u]+=f.wt, D[u]+=f.t;
Order[big[u]].erase(Order[big[u]].begin());
} else {
break;
}
}
Order[big[u]].insert(Job {U[u], D[u]});
}
LL scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d) {
N=p.size();
for(int i=0; i<N; i++) {
if (i) {chd[p[i]].push_back(i);}
U[i]=u[i], D[i]=d[i];
}
LL time=0;
dfs(0);
for (Job j: Order[big[0]]) {
time+=j.t;
ans+=j.wt*time;
}
return(ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
21496 KB |
Output is correct |
2 |
Correct |
18 ms |
21496 KB |
Output is correct |
3 |
Correct |
18 ms |
21496 KB |
Output is correct |
4 |
Correct |
19 ms |
21620 KB |
Output is correct |
5 |
Correct |
54 ms |
30712 KB |
Output is correct |
6 |
Correct |
82 ms |
39800 KB |
Output is correct |
7 |
Correct |
111 ms |
49048 KB |
Output is correct |
8 |
Correct |
143 ms |
58232 KB |
Output is correct |
9 |
Correct |
144 ms |
58448 KB |
Output is correct |
10 |
Correct |
140 ms |
58232 KB |
Output is correct |
11 |
Correct |
18 ms |
21496 KB |
Output is correct |
12 |
Correct |
142 ms |
58232 KB |
Output is correct |
13 |
Correct |
137 ms |
58360 KB |
Output is correct |
14 |
Correct |
157 ms |
58360 KB |
Output is correct |
15 |
Correct |
138 ms |
58548 KB |
Output is correct |
16 |
Correct |
159 ms |
58488 KB |
Output is correct |
17 |
Correct |
142 ms |
58360 KB |
Output is correct |
18 |
Correct |
149 ms |
58360 KB |
Output is correct |
19 |
Correct |
135 ms |
58360 KB |
Output is correct |
20 |
Correct |
186 ms |
66936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
21496 KB |
Output is correct |
2 |
Correct |
18 ms |
21496 KB |
Output is correct |
3 |
Correct |
18 ms |
21496 KB |
Output is correct |
4 |
Correct |
328 ms |
57708 KB |
Output is correct |
5 |
Correct |
342 ms |
57684 KB |
Output is correct |
6 |
Correct |
325 ms |
57708 KB |
Output is correct |
7 |
Correct |
332 ms |
57708 KB |
Output is correct |
8 |
Correct |
325 ms |
57708 KB |
Output is correct |
9 |
Correct |
331 ms |
57708 KB |
Output is correct |
10 |
Correct |
345 ms |
57708 KB |
Output is correct |
11 |
Correct |
336 ms |
57720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
21496 KB |
Output is correct |
2 |
Correct |
17 ms |
21496 KB |
Output is correct |
3 |
Correct |
18 ms |
21496 KB |
Output is correct |
4 |
Correct |
18 ms |
21624 KB |
Output is correct |
5 |
Correct |
27 ms |
23416 KB |
Output is correct |
6 |
Correct |
316 ms |
58220 KB |
Output is correct |
7 |
Correct |
328 ms |
58220 KB |
Output is correct |
8 |
Correct |
328 ms |
58220 KB |
Output is correct |
9 |
Correct |
321 ms |
58220 KB |
Output is correct |
10 |
Correct |
18 ms |
21496 KB |
Output is correct |
11 |
Correct |
20 ms |
21752 KB |
Output is correct |
12 |
Correct |
26 ms |
23032 KB |
Output is correct |
13 |
Correct |
27 ms |
23288 KB |
Output is correct |
14 |
Correct |
330 ms |
58304 KB |
Output is correct |
15 |
Correct |
332 ms |
58220 KB |
Output is correct |
16 |
Correct |
317 ms |
58280 KB |
Output is correct |
17 |
Correct |
341 ms |
58220 KB |
Output is correct |
18 |
Correct |
334 ms |
58348 KB |
Output is correct |
19 |
Correct |
323 ms |
58224 KB |
Output is correct |
20 |
Correct |
314 ms |
58220 KB |
Output is correct |
21 |
Correct |
317 ms |
58348 KB |
Output is correct |
22 |
Correct |
322 ms |
58220 KB |
Output is correct |
23 |
Correct |
327 ms |
58352 KB |
Output is correct |
24 |
Correct |
328 ms |
58220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
21496 KB |
Output is correct |
2 |
Correct |
143 ms |
48888 KB |
Output is correct |
3 |
Correct |
146 ms |
48888 KB |
Output is correct |
4 |
Correct |
150 ms |
49144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
21496 KB |
Output is correct |
2 |
Correct |
18 ms |
21496 KB |
Output is correct |
3 |
Correct |
18 ms |
21496 KB |
Output is correct |
4 |
Correct |
20 ms |
21500 KB |
Output is correct |
5 |
Correct |
20 ms |
21496 KB |
Output is correct |
6 |
Correct |
17 ms |
21624 KB |
Output is correct |
7 |
Correct |
18 ms |
21496 KB |
Output is correct |
8 |
Correct |
18 ms |
21496 KB |
Output is correct |
9 |
Correct |
18 ms |
21528 KB |
Output is correct |
10 |
Correct |
20 ms |
21496 KB |
Output is correct |
11 |
Correct |
20 ms |
21496 KB |
Output is correct |
12 |
Correct |
19 ms |
21496 KB |
Output is correct |
13 |
Correct |
18 ms |
21496 KB |
Output is correct |
14 |
Correct |
17 ms |
21496 KB |
Output is correct |
15 |
Correct |
18 ms |
21496 KB |
Output is correct |
16 |
Correct |
19 ms |
21496 KB |
Output is correct |
17 |
Correct |
20 ms |
21496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
21496 KB |
Output is correct |
2 |
Correct |
18 ms |
21496 KB |
Output is correct |
3 |
Correct |
18 ms |
21496 KB |
Output is correct |
4 |
Correct |
19 ms |
21620 KB |
Output is correct |
5 |
Correct |
54 ms |
30712 KB |
Output is correct |
6 |
Correct |
82 ms |
39800 KB |
Output is correct |
7 |
Correct |
111 ms |
49048 KB |
Output is correct |
8 |
Correct |
143 ms |
58232 KB |
Output is correct |
9 |
Correct |
144 ms |
58448 KB |
Output is correct |
10 |
Correct |
140 ms |
58232 KB |
Output is correct |
11 |
Correct |
18 ms |
21496 KB |
Output is correct |
12 |
Correct |
142 ms |
58232 KB |
Output is correct |
13 |
Correct |
137 ms |
58360 KB |
Output is correct |
14 |
Correct |
157 ms |
58360 KB |
Output is correct |
15 |
Correct |
138 ms |
58548 KB |
Output is correct |
16 |
Correct |
159 ms |
58488 KB |
Output is correct |
17 |
Correct |
142 ms |
58360 KB |
Output is correct |
18 |
Correct |
149 ms |
58360 KB |
Output is correct |
19 |
Correct |
135 ms |
58360 KB |
Output is correct |
20 |
Correct |
186 ms |
66936 KB |
Output is correct |
21 |
Correct |
17 ms |
21496 KB |
Output is correct |
22 |
Correct |
18 ms |
21496 KB |
Output is correct |
23 |
Correct |
18 ms |
21496 KB |
Output is correct |
24 |
Correct |
328 ms |
57708 KB |
Output is correct |
25 |
Correct |
342 ms |
57684 KB |
Output is correct |
26 |
Correct |
325 ms |
57708 KB |
Output is correct |
27 |
Correct |
332 ms |
57708 KB |
Output is correct |
28 |
Correct |
325 ms |
57708 KB |
Output is correct |
29 |
Correct |
331 ms |
57708 KB |
Output is correct |
30 |
Correct |
345 ms |
57708 KB |
Output is correct |
31 |
Correct |
336 ms |
57720 KB |
Output is correct |
32 |
Correct |
18 ms |
21496 KB |
Output is correct |
33 |
Correct |
17 ms |
21496 KB |
Output is correct |
34 |
Correct |
18 ms |
21496 KB |
Output is correct |
35 |
Correct |
18 ms |
21624 KB |
Output is correct |
36 |
Correct |
27 ms |
23416 KB |
Output is correct |
37 |
Correct |
316 ms |
58220 KB |
Output is correct |
38 |
Correct |
328 ms |
58220 KB |
Output is correct |
39 |
Correct |
328 ms |
58220 KB |
Output is correct |
40 |
Correct |
321 ms |
58220 KB |
Output is correct |
41 |
Correct |
18 ms |
21496 KB |
Output is correct |
42 |
Correct |
20 ms |
21752 KB |
Output is correct |
43 |
Correct |
26 ms |
23032 KB |
Output is correct |
44 |
Correct |
27 ms |
23288 KB |
Output is correct |
45 |
Correct |
330 ms |
58304 KB |
Output is correct |
46 |
Correct |
332 ms |
58220 KB |
Output is correct |
47 |
Correct |
317 ms |
58280 KB |
Output is correct |
48 |
Correct |
341 ms |
58220 KB |
Output is correct |
49 |
Correct |
334 ms |
58348 KB |
Output is correct |
50 |
Correct |
323 ms |
58224 KB |
Output is correct |
51 |
Correct |
314 ms |
58220 KB |
Output is correct |
52 |
Correct |
317 ms |
58348 KB |
Output is correct |
53 |
Correct |
322 ms |
58220 KB |
Output is correct |
54 |
Correct |
327 ms |
58352 KB |
Output is correct |
55 |
Correct |
328 ms |
58220 KB |
Output is correct |
56 |
Correct |
18 ms |
21496 KB |
Output is correct |
57 |
Correct |
143 ms |
48888 KB |
Output is correct |
58 |
Correct |
146 ms |
48888 KB |
Output is correct |
59 |
Correct |
150 ms |
49144 KB |
Output is correct |
60 |
Correct |
18 ms |
21496 KB |
Output is correct |
61 |
Correct |
18 ms |
21496 KB |
Output is correct |
62 |
Correct |
18 ms |
21496 KB |
Output is correct |
63 |
Correct |
20 ms |
21500 KB |
Output is correct |
64 |
Correct |
20 ms |
21496 KB |
Output is correct |
65 |
Correct |
17 ms |
21624 KB |
Output is correct |
66 |
Correct |
18 ms |
21496 KB |
Output is correct |
67 |
Correct |
18 ms |
21496 KB |
Output is correct |
68 |
Correct |
18 ms |
21528 KB |
Output is correct |
69 |
Correct |
20 ms |
21496 KB |
Output is correct |
70 |
Correct |
20 ms |
21496 KB |
Output is correct |
71 |
Correct |
19 ms |
21496 KB |
Output is correct |
72 |
Correct |
18 ms |
21496 KB |
Output is correct |
73 |
Correct |
17 ms |
21496 KB |
Output is correct |
74 |
Correct |
18 ms |
21496 KB |
Output is correct |
75 |
Correct |
19 ms |
21496 KB |
Output is correct |
76 |
Correct |
20 ms |
21496 KB |
Output is correct |
77 |
Correct |
19 ms |
21496 KB |
Output is correct |
78 |
Correct |
18 ms |
21404 KB |
Output is correct |
79 |
Correct |
19 ms |
21496 KB |
Output is correct |
80 |
Correct |
19 ms |
21496 KB |
Output is correct |
81 |
Correct |
18 ms |
21496 KB |
Output is correct |
82 |
Correct |
19 ms |
21496 KB |
Output is correct |
83 |
Correct |
20 ms |
21496 KB |
Output is correct |
84 |
Correct |
18 ms |
21496 KB |
Output is correct |
85 |
Correct |
18 ms |
21496 KB |
Output is correct |
86 |
Correct |
18 ms |
21496 KB |
Output is correct |
87 |
Correct |
18 ms |
21496 KB |
Output is correct |
88 |
Correct |
25 ms |
22520 KB |
Output is correct |
89 |
Correct |
27 ms |
23160 KB |
Output is correct |
90 |
Correct |
29 ms |
23672 KB |
Output is correct |
91 |
Correct |
87 ms |
33784 KB |
Output is correct |
92 |
Correct |
177 ms |
46840 KB |
Output is correct |
93 |
Correct |
351 ms |
72952 KB |
Output is correct |
94 |
Correct |
369 ms |
74016 KB |
Output is correct |
95 |
Correct |
372 ms |
73740 KB |
Output is correct |
96 |
Correct |
354 ms |
73464 KB |
Output is correct |
97 |
Correct |
349 ms |
74104 KB |
Output is correct |
98 |
Correct |
343 ms |
78712 KB |
Output is correct |
99 |
Correct |
371 ms |
84244 KB |
Output is correct |
100 |
Correct |
357 ms |
73464 KB |
Output is correct |
101 |
Correct |
270 ms |
62840 KB |
Output is correct |
102 |
Correct |
423 ms |
101520 KB |
Output is correct |
103 |
Correct |
306 ms |
62200 KB |
Output is correct |
104 |
Correct |
268 ms |
55032 KB |
Output is correct |
105 |
Correct |
204 ms |
50680 KB |
Output is correct |
106 |
Correct |
382 ms |
70648 KB |
Output is correct |