#include "bits/stdc++.h"
#include "job.h"
using namespace std;
const int maxn = 2e5 + 5;
int n, w[maxn], t[maxn], p[maxn];
vector<int> g[maxn];
struct info {
long long w, t, total;
void merge(const info &o) {
total += o.total + t * o.w;
w += o.w;
t += o.t;
}
bool operator<(const info &o) const {
return w * o.t > o.w * t;
}
bool operator>(const info &o) const {
return w * o.t < o.w * t;
}
};
priority_queue<info, vector<info>, greater<info>> pq[maxn];
void dfs(int u) {
for(auto v:g[u]) {
dfs(v);
if(pq[u].size() < pq[v].size()) {
swap(pq[u], pq[v]);
}
while(!pq[v].empty()) {
pq[u].push(pq[v].top());
pq[v].pop();
}
}
info cur = {w[u], t[u], 1ll * w[u] * t[u]};
while(!pq[u].empty()) {
info top = pq[u].top();
if(cur < top) break;
cur.merge(pq[u].top());
pq[u].pop();
}
pq[u].push(cur);
}
long long scheduling_cost(vector<int> _p, vector<int> _w, vector<int> _t) {
n = _p.size();
for(int i = 0; i < n; ++i) {
p[i] = _p[i];
w[i] = _w[i];
t[i] = _t[i];
if(p[i] != -1) {
g[p[i]].push_back(i);
}
}
dfs(0);
info cur = {0, 0, 0};
while(!pq[0].empty()) {
cur.merge(pq[0].top());
pq[0].pop();
}
return cur.total;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
11352 KB |
Output is correct |
2 |
Correct |
4 ms |
11356 KB |
Output is correct |
3 |
Correct |
5 ms |
11356 KB |
Output is correct |
4 |
Correct |
5 ms |
11612 KB |
Output is correct |
5 |
Correct |
22 ms |
22364 KB |
Output is correct |
6 |
Correct |
39 ms |
33624 KB |
Output is correct |
7 |
Correct |
62 ms |
44780 KB |
Output is correct |
8 |
Correct |
72 ms |
55888 KB |
Output is correct |
9 |
Correct |
82 ms |
55892 KB |
Output is correct |
10 |
Correct |
71 ms |
55892 KB |
Output is correct |
11 |
Correct |
5 ms |
11356 KB |
Output is correct |
12 |
Correct |
77 ms |
55844 KB |
Output is correct |
13 |
Correct |
70 ms |
55892 KB |
Output is correct |
14 |
Correct |
80 ms |
55888 KB |
Output is correct |
15 |
Correct |
82 ms |
55976 KB |
Output is correct |
16 |
Correct |
83 ms |
56148 KB |
Output is correct |
17 |
Correct |
74 ms |
55892 KB |
Output is correct |
18 |
Correct |
73 ms |
55840 KB |
Output is correct |
19 |
Correct |
68 ms |
55888 KB |
Output is correct |
20 |
Correct |
98 ms |
62276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
11352 KB |
Output is correct |
2 |
Correct |
5 ms |
11608 KB |
Output is correct |
3 |
Correct |
5 ms |
11356 KB |
Output is correct |
4 |
Correct |
89 ms |
31928 KB |
Output is correct |
5 |
Correct |
103 ms |
31932 KB |
Output is correct |
6 |
Correct |
83 ms |
31928 KB |
Output is correct |
7 |
Correct |
84 ms |
31928 KB |
Output is correct |
8 |
Correct |
85 ms |
31780 KB |
Output is correct |
9 |
Correct |
100 ms |
31856 KB |
Output is correct |
10 |
Correct |
79 ms |
31928 KB |
Output is correct |
11 |
Correct |
90 ms |
31928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
11352 KB |
Output is correct |
2 |
Correct |
4 ms |
11356 KB |
Output is correct |
3 |
Correct |
4 ms |
11208 KB |
Output is correct |
4 |
Correct |
4 ms |
11352 KB |
Output is correct |
5 |
Correct |
8 ms |
12424 KB |
Output is correct |
6 |
Correct |
90 ms |
32444 KB |
Output is correct |
7 |
Correct |
87 ms |
32256 KB |
Output is correct |
8 |
Correct |
80 ms |
32268 KB |
Output is correct |
9 |
Correct |
85 ms |
32288 KB |
Output is correct |
10 |
Correct |
4 ms |
11356 KB |
Output is correct |
11 |
Correct |
5 ms |
11356 KB |
Output is correct |
12 |
Correct |
8 ms |
12376 KB |
Output is correct |
13 |
Correct |
8 ms |
12440 KB |
Output is correct |
14 |
Correct |
87 ms |
32440 KB |
Output is correct |
15 |
Correct |
81 ms |
32444 KB |
Output is correct |
16 |
Correct |
92 ms |
32428 KB |
Output is correct |
17 |
Correct |
85 ms |
32440 KB |
Output is correct |
18 |
Correct |
87 ms |
32440 KB |
Output is correct |
19 |
Correct |
94 ms |
32500 KB |
Output is correct |
20 |
Correct |
91 ms |
32440 KB |
Output is correct |
21 |
Correct |
87 ms |
32372 KB |
Output is correct |
22 |
Correct |
88 ms |
32440 KB |
Output is correct |
23 |
Correct |
82 ms |
32296 KB |
Output is correct |
24 |
Correct |
91 ms |
32444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
11352 KB |
Output is correct |
2 |
Correct |
67 ms |
41760 KB |
Output is correct |
3 |
Correct |
65 ms |
41760 KB |
Output is correct |
4 |
Correct |
68 ms |
41812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
11356 KB |
Output is correct |
2 |
Correct |
5 ms |
11356 KB |
Output is correct |
3 |
Correct |
7 ms |
11356 KB |
Output is correct |
4 |
Correct |
5 ms |
11356 KB |
Output is correct |
5 |
Correct |
5 ms |
11356 KB |
Output is correct |
6 |
Correct |
5 ms |
11356 KB |
Output is correct |
7 |
Correct |
5 ms |
11356 KB |
Output is correct |
8 |
Correct |
4 ms |
11400 KB |
Output is correct |
9 |
Correct |
5 ms |
11356 KB |
Output is correct |
10 |
Correct |
5 ms |
11356 KB |
Output is correct |
11 |
Correct |
4 ms |
11356 KB |
Output is correct |
12 |
Correct |
5 ms |
11352 KB |
Output is correct |
13 |
Correct |
5 ms |
11356 KB |
Output is correct |
14 |
Correct |
5 ms |
11408 KB |
Output is correct |
15 |
Correct |
5 ms |
11352 KB |
Output is correct |
16 |
Correct |
5 ms |
11356 KB |
Output is correct |
17 |
Correct |
5 ms |
11356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
11352 KB |
Output is correct |
2 |
Correct |
4 ms |
11356 KB |
Output is correct |
3 |
Correct |
5 ms |
11356 KB |
Output is correct |
4 |
Correct |
5 ms |
11612 KB |
Output is correct |
5 |
Correct |
22 ms |
22364 KB |
Output is correct |
6 |
Correct |
39 ms |
33624 KB |
Output is correct |
7 |
Correct |
62 ms |
44780 KB |
Output is correct |
8 |
Correct |
72 ms |
55888 KB |
Output is correct |
9 |
Correct |
82 ms |
55892 KB |
Output is correct |
10 |
Correct |
71 ms |
55892 KB |
Output is correct |
11 |
Correct |
5 ms |
11356 KB |
Output is correct |
12 |
Correct |
77 ms |
55844 KB |
Output is correct |
13 |
Correct |
70 ms |
55892 KB |
Output is correct |
14 |
Correct |
80 ms |
55888 KB |
Output is correct |
15 |
Correct |
82 ms |
55976 KB |
Output is correct |
16 |
Correct |
83 ms |
56148 KB |
Output is correct |
17 |
Correct |
74 ms |
55892 KB |
Output is correct |
18 |
Correct |
73 ms |
55840 KB |
Output is correct |
19 |
Correct |
68 ms |
55888 KB |
Output is correct |
20 |
Correct |
98 ms |
62276 KB |
Output is correct |
21 |
Correct |
4 ms |
11352 KB |
Output is correct |
22 |
Correct |
5 ms |
11608 KB |
Output is correct |
23 |
Correct |
5 ms |
11356 KB |
Output is correct |
24 |
Correct |
89 ms |
31928 KB |
Output is correct |
25 |
Correct |
103 ms |
31932 KB |
Output is correct |
26 |
Correct |
83 ms |
31928 KB |
Output is correct |
27 |
Correct |
84 ms |
31928 KB |
Output is correct |
28 |
Correct |
85 ms |
31780 KB |
Output is correct |
29 |
Correct |
100 ms |
31856 KB |
Output is correct |
30 |
Correct |
79 ms |
31928 KB |
Output is correct |
31 |
Correct |
90 ms |
31928 KB |
Output is correct |
32 |
Correct |
4 ms |
11352 KB |
Output is correct |
33 |
Correct |
4 ms |
11356 KB |
Output is correct |
34 |
Correct |
4 ms |
11208 KB |
Output is correct |
35 |
Correct |
4 ms |
11352 KB |
Output is correct |
36 |
Correct |
8 ms |
12424 KB |
Output is correct |
37 |
Correct |
90 ms |
32444 KB |
Output is correct |
38 |
Correct |
87 ms |
32256 KB |
Output is correct |
39 |
Correct |
80 ms |
32268 KB |
Output is correct |
40 |
Correct |
85 ms |
32288 KB |
Output is correct |
41 |
Correct |
4 ms |
11356 KB |
Output is correct |
42 |
Correct |
5 ms |
11356 KB |
Output is correct |
43 |
Correct |
8 ms |
12376 KB |
Output is correct |
44 |
Correct |
8 ms |
12440 KB |
Output is correct |
45 |
Correct |
87 ms |
32440 KB |
Output is correct |
46 |
Correct |
81 ms |
32444 KB |
Output is correct |
47 |
Correct |
92 ms |
32428 KB |
Output is correct |
48 |
Correct |
85 ms |
32440 KB |
Output is correct |
49 |
Correct |
87 ms |
32440 KB |
Output is correct |
50 |
Correct |
94 ms |
32500 KB |
Output is correct |
51 |
Correct |
91 ms |
32440 KB |
Output is correct |
52 |
Correct |
87 ms |
32372 KB |
Output is correct |
53 |
Correct |
88 ms |
32440 KB |
Output is correct |
54 |
Correct |
82 ms |
32296 KB |
Output is correct |
55 |
Correct |
91 ms |
32444 KB |
Output is correct |
56 |
Correct |
4 ms |
11352 KB |
Output is correct |
57 |
Correct |
67 ms |
41760 KB |
Output is correct |
58 |
Correct |
65 ms |
41760 KB |
Output is correct |
59 |
Correct |
68 ms |
41812 KB |
Output is correct |
60 |
Correct |
4 ms |
11356 KB |
Output is correct |
61 |
Correct |
5 ms |
11356 KB |
Output is correct |
62 |
Correct |
7 ms |
11356 KB |
Output is correct |
63 |
Correct |
5 ms |
11356 KB |
Output is correct |
64 |
Correct |
5 ms |
11356 KB |
Output is correct |
65 |
Correct |
5 ms |
11356 KB |
Output is correct |
66 |
Correct |
5 ms |
11356 KB |
Output is correct |
67 |
Correct |
4 ms |
11400 KB |
Output is correct |
68 |
Correct |
5 ms |
11356 KB |
Output is correct |
69 |
Correct |
5 ms |
11356 KB |
Output is correct |
70 |
Correct |
4 ms |
11356 KB |
Output is correct |
71 |
Correct |
5 ms |
11352 KB |
Output is correct |
72 |
Correct |
5 ms |
11356 KB |
Output is correct |
73 |
Correct |
5 ms |
11408 KB |
Output is correct |
74 |
Correct |
5 ms |
11352 KB |
Output is correct |
75 |
Correct |
5 ms |
11356 KB |
Output is correct |
76 |
Correct |
5 ms |
11356 KB |
Output is correct |
77 |
Correct |
5 ms |
11356 KB |
Output is correct |
78 |
Correct |
5 ms |
11352 KB |
Output is correct |
79 |
Correct |
5 ms |
11356 KB |
Output is correct |
80 |
Correct |
4 ms |
11356 KB |
Output is correct |
81 |
Correct |
4 ms |
11356 KB |
Output is correct |
82 |
Correct |
5 ms |
11356 KB |
Output is correct |
83 |
Correct |
4 ms |
11356 KB |
Output is correct |
84 |
Correct |
4 ms |
11356 KB |
Output is correct |
85 |
Correct |
5 ms |
11356 KB |
Output is correct |
86 |
Correct |
5 ms |
11356 KB |
Output is correct |
87 |
Correct |
4 ms |
11356 KB |
Output is correct |
88 |
Correct |
8 ms |
12120 KB |
Output is correct |
89 |
Correct |
9 ms |
12380 KB |
Output is correct |
90 |
Correct |
9 ms |
12636 KB |
Output is correct |
91 |
Correct |
35 ms |
19024 KB |
Output is correct |
92 |
Correct |
62 ms |
26644 KB |
Output is correct |
93 |
Correct |
132 ms |
42220 KB |
Output is correct |
94 |
Correct |
133 ms |
42752 KB |
Output is correct |
95 |
Correct |
136 ms |
42504 KB |
Output is correct |
96 |
Correct |
124 ms |
42248 KB |
Output is correct |
97 |
Correct |
134 ms |
42460 KB |
Output is correct |
98 |
Correct |
147 ms |
45256 KB |
Output is correct |
99 |
Correct |
138 ms |
46288 KB |
Output is correct |
100 |
Correct |
155 ms |
42432 KB |
Output is correct |
101 |
Correct |
118 ms |
39176 KB |
Output is correct |
102 |
Correct |
179 ms |
54480 KB |
Output is correct |
103 |
Correct |
119 ms |
37380 KB |
Output is correct |
104 |
Correct |
96 ms |
35148 KB |
Output is correct |
105 |
Correct |
98 ms |
33500 KB |
Output is correct |
106 |
Correct |
107 ms |
38136 KB |
Output is correct |