#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);
}
# |
결과 |
실행 시간 |
메모리 |
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 |
21624 KB |
Output is correct |
5 |
Correct |
49 ms |
30200 KB |
Output is correct |
6 |
Correct |
79 ms |
38652 KB |
Output is correct |
7 |
Correct |
117 ms |
47224 KB |
Output is correct |
8 |
Correct |
142 ms |
55544 KB |
Output is correct |
9 |
Correct |
141 ms |
55544 KB |
Output is correct |
10 |
Correct |
140 ms |
55544 KB |
Output is correct |
11 |
Correct |
20 ms |
21496 KB |
Output is correct |
12 |
Correct |
142 ms |
55536 KB |
Output is correct |
13 |
Correct |
139 ms |
55544 KB |
Output is correct |
14 |
Correct |
143 ms |
55572 KB |
Output is correct |
15 |
Correct |
136 ms |
55544 KB |
Output is correct |
16 |
Correct |
158 ms |
55672 KB |
Output is correct |
17 |
Correct |
142 ms |
55544 KB |
Output is correct |
18 |
Correct |
144 ms |
55544 KB |
Output is correct |
19 |
Correct |
136 ms |
55544 KB |
Output is correct |
20 |
Correct |
187 ms |
64120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
21496 KB |
Output is correct |
2 |
Correct |
18 ms |
21496 KB |
Output is correct |
3 |
Correct |
21 ms |
21496 KB |
Output is correct |
4 |
Correct |
337 ms |
56300 KB |
Output is correct |
5 |
Correct |
340 ms |
56300 KB |
Output is correct |
6 |
Correct |
344 ms |
56428 KB |
Output is correct |
7 |
Correct |
347 ms |
56428 KB |
Output is correct |
8 |
Correct |
333 ms |
56300 KB |
Output is correct |
9 |
Correct |
344 ms |
56300 KB |
Output is correct |
10 |
Correct |
341 ms |
56300 KB |
Output is correct |
11 |
Correct |
334 ms |
56300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
21496 KB |
Output is correct |
2 |
Correct |
18 ms |
21496 KB |
Output is correct |
3 |
Correct |
19 ms |
21496 KB |
Output is correct |
4 |
Correct |
19 ms |
21624 KB |
Output is correct |
5 |
Correct |
27 ms |
23288 KB |
Output is correct |
6 |
Correct |
320 ms |
56428 KB |
Output is correct |
7 |
Correct |
324 ms |
56428 KB |
Output is correct |
8 |
Correct |
324 ms |
56300 KB |
Output is correct |
9 |
Correct |
323 ms |
56392 KB |
Output is correct |
10 |
Correct |
18 ms |
21496 KB |
Output is correct |
11 |
Correct |
19 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 |
333 ms |
56432 KB |
Output is correct |
15 |
Correct |
313 ms |
56300 KB |
Output is correct |
16 |
Correct |
324 ms |
56428 KB |
Output is correct |
17 |
Correct |
318 ms |
56300 KB |
Output is correct |
18 |
Correct |
318 ms |
56300 KB |
Output is correct |
19 |
Correct |
318 ms |
56396 KB |
Output is correct |
20 |
Correct |
317 ms |
56300 KB |
Output is correct |
21 |
Correct |
327 ms |
56300 KB |
Output is correct |
22 |
Correct |
314 ms |
56300 KB |
Output is correct |
23 |
Correct |
337 ms |
56428 KB |
Output is correct |
24 |
Correct |
314 ms |
56304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
21496 KB |
Output is correct |
2 |
Correct |
144 ms |
46072 KB |
Output is correct |
3 |
Correct |
136 ms |
46200 KB |
Output is correct |
4 |
Correct |
151 ms |
46072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
21496 KB |
Output is correct |
2 |
Correct |
20 ms |
21492 KB |
Output is correct |
3 |
Correct |
19 ms |
21496 KB |
Output is correct |
4 |
Correct |
21 ms |
21496 KB |
Output is correct |
5 |
Correct |
19 ms |
21496 KB |
Output is correct |
6 |
Correct |
18 ms |
21500 KB |
Output is correct |
7 |
Correct |
18 ms |
21496 KB |
Output is correct |
8 |
Correct |
18 ms |
21496 KB |
Output is correct |
9 |
Correct |
19 ms |
21500 KB |
Output is correct |
10 |
Correct |
18 ms |
21624 KB |
Output is correct |
11 |
Correct |
19 ms |
21496 KB |
Output is correct |
12 |
Correct |
18 ms |
21496 KB |
Output is correct |
13 |
Correct |
19 ms |
21496 KB |
Output is correct |
14 |
Correct |
19 ms |
21500 KB |
Output is correct |
15 |
Correct |
18 ms |
21496 KB |
Output is correct |
16 |
Correct |
19 ms |
21500 KB |
Output is correct |
17 |
Correct |
19 ms |
21496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
21624 KB |
Output is correct |
5 |
Correct |
49 ms |
30200 KB |
Output is correct |
6 |
Correct |
79 ms |
38652 KB |
Output is correct |
7 |
Correct |
117 ms |
47224 KB |
Output is correct |
8 |
Correct |
142 ms |
55544 KB |
Output is correct |
9 |
Correct |
141 ms |
55544 KB |
Output is correct |
10 |
Correct |
140 ms |
55544 KB |
Output is correct |
11 |
Correct |
20 ms |
21496 KB |
Output is correct |
12 |
Correct |
142 ms |
55536 KB |
Output is correct |
13 |
Correct |
139 ms |
55544 KB |
Output is correct |
14 |
Correct |
143 ms |
55572 KB |
Output is correct |
15 |
Correct |
136 ms |
55544 KB |
Output is correct |
16 |
Correct |
158 ms |
55672 KB |
Output is correct |
17 |
Correct |
142 ms |
55544 KB |
Output is correct |
18 |
Correct |
144 ms |
55544 KB |
Output is correct |
19 |
Correct |
136 ms |
55544 KB |
Output is correct |
20 |
Correct |
187 ms |
64120 KB |
Output is correct |
21 |
Correct |
19 ms |
21496 KB |
Output is correct |
22 |
Correct |
18 ms |
21496 KB |
Output is correct |
23 |
Correct |
21 ms |
21496 KB |
Output is correct |
24 |
Correct |
337 ms |
56300 KB |
Output is correct |
25 |
Correct |
340 ms |
56300 KB |
Output is correct |
26 |
Correct |
344 ms |
56428 KB |
Output is correct |
27 |
Correct |
347 ms |
56428 KB |
Output is correct |
28 |
Correct |
333 ms |
56300 KB |
Output is correct |
29 |
Correct |
344 ms |
56300 KB |
Output is correct |
30 |
Correct |
341 ms |
56300 KB |
Output is correct |
31 |
Correct |
334 ms |
56300 KB |
Output is correct |
32 |
Correct |
18 ms |
21496 KB |
Output is correct |
33 |
Correct |
18 ms |
21496 KB |
Output is correct |
34 |
Correct |
19 ms |
21496 KB |
Output is correct |
35 |
Correct |
19 ms |
21624 KB |
Output is correct |
36 |
Correct |
27 ms |
23288 KB |
Output is correct |
37 |
Correct |
320 ms |
56428 KB |
Output is correct |
38 |
Correct |
324 ms |
56428 KB |
Output is correct |
39 |
Correct |
324 ms |
56300 KB |
Output is correct |
40 |
Correct |
323 ms |
56392 KB |
Output is correct |
41 |
Correct |
18 ms |
21496 KB |
Output is correct |
42 |
Correct |
19 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 |
333 ms |
56432 KB |
Output is correct |
46 |
Correct |
313 ms |
56300 KB |
Output is correct |
47 |
Correct |
324 ms |
56428 KB |
Output is correct |
48 |
Correct |
318 ms |
56300 KB |
Output is correct |
49 |
Correct |
318 ms |
56300 KB |
Output is correct |
50 |
Correct |
318 ms |
56396 KB |
Output is correct |
51 |
Correct |
317 ms |
56300 KB |
Output is correct |
52 |
Correct |
327 ms |
56300 KB |
Output is correct |
53 |
Correct |
314 ms |
56300 KB |
Output is correct |
54 |
Correct |
337 ms |
56428 KB |
Output is correct |
55 |
Correct |
314 ms |
56304 KB |
Output is correct |
56 |
Correct |
18 ms |
21496 KB |
Output is correct |
57 |
Correct |
144 ms |
46072 KB |
Output is correct |
58 |
Correct |
136 ms |
46200 KB |
Output is correct |
59 |
Correct |
151 ms |
46072 KB |
Output is correct |
60 |
Correct |
18 ms |
21496 KB |
Output is correct |
61 |
Correct |
20 ms |
21492 KB |
Output is correct |
62 |
Correct |
19 ms |
21496 KB |
Output is correct |
63 |
Correct |
21 ms |
21496 KB |
Output is correct |
64 |
Correct |
19 ms |
21496 KB |
Output is correct |
65 |
Correct |
18 ms |
21500 KB |
Output is correct |
66 |
Correct |
18 ms |
21496 KB |
Output is correct |
67 |
Correct |
18 ms |
21496 KB |
Output is correct |
68 |
Correct |
19 ms |
21500 KB |
Output is correct |
69 |
Correct |
18 ms |
21624 KB |
Output is correct |
70 |
Correct |
19 ms |
21496 KB |
Output is correct |
71 |
Correct |
18 ms |
21496 KB |
Output is correct |
72 |
Correct |
19 ms |
21496 KB |
Output is correct |
73 |
Correct |
19 ms |
21500 KB |
Output is correct |
74 |
Correct |
18 ms |
21496 KB |
Output is correct |
75 |
Correct |
19 ms |
21500 KB |
Output is correct |
76 |
Correct |
19 ms |
21496 KB |
Output is correct |
77 |
Correct |
19 ms |
21496 KB |
Output is correct |
78 |
Correct |
18 ms |
21624 KB |
Output is correct |
79 |
Correct |
19 ms |
21496 KB |
Output is correct |
80 |
Correct |
19 ms |
21500 KB |
Output is correct |
81 |
Correct |
19 ms |
21496 KB |
Output is correct |
82 |
Correct |
18 ms |
21496 KB |
Output is correct |
83 |
Correct |
19 ms |
21496 KB |
Output is correct |
84 |
Correct |
19 ms |
21496 KB |
Output is correct |
85 |
Correct |
18 ms |
21496 KB |
Output is correct |
86 |
Correct |
19 ms |
21496 KB |
Output is correct |
87 |
Correct |
18 ms |
21496 KB |
Output is correct |
88 |
Correct |
24 ms |
22520 KB |
Output is correct |
89 |
Correct |
26 ms |
23160 KB |
Output is correct |
90 |
Correct |
28 ms |
23672 KB |
Output is correct |
91 |
Correct |
87 ms |
33400 KB |
Output is correct |
92 |
Correct |
168 ms |
46004 KB |
Output is correct |
93 |
Correct |
334 ms |
70012 KB |
Output is correct |
94 |
Correct |
343 ms |
71160 KB |
Output is correct |
95 |
Correct |
334 ms |
70904 KB |
Output is correct |
96 |
Correct |
348 ms |
70776 KB |
Output is correct |
97 |
Correct |
327 ms |
71288 KB |
Output is correct |
98 |
Correct |
343 ms |
75768 KB |
Output is correct |
99 |
Correct |
370 ms |
81528 KB |
Output is correct |
100 |
Correct |
336 ms |
70392 KB |
Output is correct |
101 |
Correct |
271 ms |
60152 KB |
Output is correct |
102 |
Correct |
418 ms |
98680 KB |
Output is correct |
103 |
Correct |
295 ms |
59540 KB |
Output is correct |
104 |
Correct |
257 ms |
52088 KB |
Output is correct |
105 |
Correct |
211 ms |
47736 KB |
Output is correct |
106 |
Correct |
382 ms |
68344 KB |
Output is correct |