#include "job.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> ord, t;
vector<vector<int>> v;
struct frac
{
int x, y, id;
};
struct cmp
{
bool operator () (frac a, frac b)
{
return (ll) a.x * b.y > (ll) b.x * a.y;
}
};
void dfs(int node)
{
ord.push_back(node);
for(auto it : v[node])
dfs(it);
}
int boss(int x)
{
if(x == t[x]) return x;
return t[x] = boss(t[x]);
}
ll scheduling_cost(vector<int> p, vector<int> u, vector<int> d)
{
priority_queue<frac, vector<frac>, cmp> heap;
vector<int> U, D;
U = u;
D = d;
int i, n = p.size();
for(i=1; i<n; ++i)
heap.push({D[i], U[i], i});
t.resize(n);
for(i=0; i<n; ++i)
t[i] = i;
v.resize(n);
while(heap.size())
{
auto el = heap.top();
heap.pop();
if(make_pair(D[el.id], U[el.id]) != make_pair(el.x, el.y)) continue;
int father = boss(p[el.id]);
t[el.id] = father;
D[father] += D[el.id];
U[father] += U[el.id];
v[father].push_back(el.id);
if(father)
heap.push({D[father], U[father], father});
}
dfs(0);
ll sum = 0, ans = 0;
for(auto it : ord)
{
sum += d[it];
ans += sum * u[it];
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
62 ms |
6128 KB |
Output is correct |
6 |
Correct |
148 ms |
12040 KB |
Output is correct |
7 |
Correct |
210 ms |
18152 KB |
Output is correct |
8 |
Correct |
362 ms |
23912 KB |
Output is correct |
9 |
Correct |
365 ms |
23924 KB |
Output is correct |
10 |
Correct |
284 ms |
23780 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
306 ms |
23988 KB |
Output is correct |
13 |
Correct |
218 ms |
33508 KB |
Output is correct |
14 |
Correct |
283 ms |
23912 KB |
Output is correct |
15 |
Correct |
200 ms |
35076 KB |
Output is correct |
16 |
Correct |
217 ms |
23908 KB |
Output is correct |
17 |
Correct |
330 ms |
23912 KB |
Output is correct |
18 |
Correct |
289 ms |
23780 KB |
Output is correct |
19 |
Correct |
194 ms |
35044 KB |
Output is correct |
20 |
Correct |
157 ms |
21736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
166 ms |
18824 KB |
Output is correct |
5 |
Correct |
149 ms |
18920 KB |
Output is correct |
6 |
Correct |
149 ms |
18792 KB |
Output is correct |
7 |
Correct |
143 ms |
18788 KB |
Output is correct |
8 |
Correct |
143 ms |
18792 KB |
Output is correct |
9 |
Correct |
166 ms |
18792 KB |
Output is correct |
10 |
Correct |
165 ms |
18792 KB |
Output is correct |
11 |
Correct |
159 ms |
18788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
416 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
1348 KB |
Output is correct |
6 |
Correct |
156 ms |
19300 KB |
Output is correct |
7 |
Correct |
164 ms |
19432 KB |
Output is correct |
8 |
Correct |
173 ms |
19432 KB |
Output is correct |
9 |
Correct |
171 ms |
19300 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
10 ms |
1220 KB |
Output is correct |
13 |
Correct |
11 ms |
1348 KB |
Output is correct |
14 |
Correct |
150 ms |
19300 KB |
Output is correct |
15 |
Correct |
148 ms |
19300 KB |
Output is correct |
16 |
Correct |
182 ms |
19572 KB |
Output is correct |
17 |
Correct |
149 ms |
19432 KB |
Output is correct |
18 |
Correct |
147 ms |
19300 KB |
Output is correct |
19 |
Correct |
172 ms |
19300 KB |
Output is correct |
20 |
Correct |
173 ms |
19408 KB |
Output is correct |
21 |
Correct |
172 ms |
19304 KB |
Output is correct |
22 |
Correct |
154 ms |
19304 KB |
Output is correct |
23 |
Correct |
164 ms |
19576 KB |
Output is correct |
24 |
Correct |
157 ms |
19304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
300 ms |
23808 KB |
Output is correct |
3 |
Correct |
296 ms |
24080 KB |
Output is correct |
4 |
Correct |
364 ms |
23780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
6 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
62 ms |
6128 KB |
Output is correct |
6 |
Correct |
148 ms |
12040 KB |
Output is correct |
7 |
Correct |
210 ms |
18152 KB |
Output is correct |
8 |
Correct |
362 ms |
23912 KB |
Output is correct |
9 |
Correct |
365 ms |
23924 KB |
Output is correct |
10 |
Correct |
284 ms |
23780 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
306 ms |
23988 KB |
Output is correct |
13 |
Correct |
218 ms |
33508 KB |
Output is correct |
14 |
Correct |
283 ms |
23912 KB |
Output is correct |
15 |
Correct |
200 ms |
35076 KB |
Output is correct |
16 |
Correct |
217 ms |
23908 KB |
Output is correct |
17 |
Correct |
330 ms |
23912 KB |
Output is correct |
18 |
Correct |
289 ms |
23780 KB |
Output is correct |
19 |
Correct |
194 ms |
35044 KB |
Output is correct |
20 |
Correct |
157 ms |
21736 KB |
Output is correct |
21 |
Correct |
4 ms |
256 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
166 ms |
18824 KB |
Output is correct |
25 |
Correct |
149 ms |
18920 KB |
Output is correct |
26 |
Correct |
149 ms |
18792 KB |
Output is correct |
27 |
Correct |
143 ms |
18788 KB |
Output is correct |
28 |
Correct |
143 ms |
18792 KB |
Output is correct |
29 |
Correct |
166 ms |
18792 KB |
Output is correct |
30 |
Correct |
165 ms |
18792 KB |
Output is correct |
31 |
Correct |
159 ms |
18788 KB |
Output is correct |
32 |
Correct |
4 ms |
256 KB |
Output is correct |
33 |
Correct |
5 ms |
256 KB |
Output is correct |
34 |
Correct |
5 ms |
416 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
11 ms |
1348 KB |
Output is correct |
37 |
Correct |
156 ms |
19300 KB |
Output is correct |
38 |
Correct |
164 ms |
19432 KB |
Output is correct |
39 |
Correct |
173 ms |
19432 KB |
Output is correct |
40 |
Correct |
171 ms |
19300 KB |
Output is correct |
41 |
Correct |
5 ms |
256 KB |
Output is correct |
42 |
Correct |
5 ms |
512 KB |
Output is correct |
43 |
Correct |
10 ms |
1220 KB |
Output is correct |
44 |
Correct |
11 ms |
1348 KB |
Output is correct |
45 |
Correct |
150 ms |
19300 KB |
Output is correct |
46 |
Correct |
148 ms |
19300 KB |
Output is correct |
47 |
Correct |
182 ms |
19572 KB |
Output is correct |
48 |
Correct |
149 ms |
19432 KB |
Output is correct |
49 |
Correct |
147 ms |
19300 KB |
Output is correct |
50 |
Correct |
172 ms |
19300 KB |
Output is correct |
51 |
Correct |
173 ms |
19408 KB |
Output is correct |
52 |
Correct |
172 ms |
19304 KB |
Output is correct |
53 |
Correct |
154 ms |
19304 KB |
Output is correct |
54 |
Correct |
164 ms |
19576 KB |
Output is correct |
55 |
Correct |
157 ms |
19304 KB |
Output is correct |
56 |
Correct |
5 ms |
256 KB |
Output is correct |
57 |
Correct |
300 ms |
23808 KB |
Output is correct |
58 |
Correct |
296 ms |
24080 KB |
Output is correct |
59 |
Correct |
364 ms |
23780 KB |
Output is correct |
60 |
Correct |
5 ms |
256 KB |
Output is correct |
61 |
Correct |
5 ms |
256 KB |
Output is correct |
62 |
Correct |
6 ms |
384 KB |
Output is correct |
63 |
Correct |
5 ms |
384 KB |
Output is correct |
64 |
Correct |
5 ms |
384 KB |
Output is correct |
65 |
Correct |
4 ms |
256 KB |
Output is correct |
66 |
Correct |
5 ms |
256 KB |
Output is correct |
67 |
Correct |
5 ms |
256 KB |
Output is correct |
68 |
Correct |
6 ms |
384 KB |
Output is correct |
69 |
Correct |
5 ms |
384 KB |
Output is correct |
70 |
Correct |
5 ms |
384 KB |
Output is correct |
71 |
Correct |
5 ms |
384 KB |
Output is correct |
72 |
Correct |
5 ms |
384 KB |
Output is correct |
73 |
Correct |
5 ms |
384 KB |
Output is correct |
74 |
Correct |
5 ms |
384 KB |
Output is correct |
75 |
Correct |
5 ms |
384 KB |
Output is correct |
76 |
Correct |
5 ms |
384 KB |
Output is correct |
77 |
Correct |
5 ms |
256 KB |
Output is correct |
78 |
Correct |
5 ms |
384 KB |
Output is correct |
79 |
Correct |
4 ms |
256 KB |
Output is correct |
80 |
Correct |
5 ms |
384 KB |
Output is correct |
81 |
Correct |
5 ms |
256 KB |
Output is correct |
82 |
Correct |
5 ms |
256 KB |
Output is correct |
83 |
Correct |
4 ms |
256 KB |
Output is correct |
84 |
Correct |
5 ms |
256 KB |
Output is correct |
85 |
Correct |
6 ms |
256 KB |
Output is correct |
86 |
Correct |
5 ms |
256 KB |
Output is correct |
87 |
Correct |
5 ms |
256 KB |
Output is correct |
88 |
Correct |
9 ms |
896 KB |
Output is correct |
89 |
Correct |
11 ms |
1152 KB |
Output is correct |
90 |
Correct |
12 ms |
1476 KB |
Output is correct |
91 |
Correct |
50 ms |
5744 KB |
Output is correct |
92 |
Correct |
118 ms |
11116 KB |
Output is correct |
93 |
Correct |
302 ms |
21864 KB |
Output is correct |
94 |
Correct |
239 ms |
21864 KB |
Output is correct |
95 |
Correct |
297 ms |
21868 KB |
Output is correct |
96 |
Correct |
240 ms |
21904 KB |
Output is correct |
97 |
Correct |
217 ms |
21476 KB |
Output is correct |
98 |
Correct |
223 ms |
21988 KB |
Output is correct |
99 |
Correct |
223 ms |
20708 KB |
Output is correct |
100 |
Correct |
298 ms |
21860 KB |
Output is correct |
101 |
Correct |
303 ms |
22376 KB |
Output is correct |
102 |
Correct |
209 ms |
20600 KB |
Output is correct |
103 |
Correct |
280 ms |
22760 KB |
Output is correct |
104 |
Correct |
284 ms |
23488 KB |
Output is correct |
105 |
Correct |
217 ms |
23652 KB |
Output is correct |
106 |
Correct |
158 ms |
20072 KB |
Output is correct |