#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 |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
504 KB |
Output is correct |
5 |
Correct |
70 ms |
6212 KB |
Output is correct |
6 |
Correct |
130 ms |
12012 KB |
Output is correct |
7 |
Correct |
211 ms |
18156 KB |
Output is correct |
8 |
Correct |
308 ms |
23908 KB |
Output is correct |
9 |
Correct |
300 ms |
23780 KB |
Output is correct |
10 |
Correct |
302 ms |
23784 KB |
Output is correct |
11 |
Correct |
5 ms |
400 KB |
Output is correct |
12 |
Correct |
300 ms |
23780 KB |
Output is correct |
13 |
Correct |
227 ms |
33480 KB |
Output is correct |
14 |
Correct |
246 ms |
23908 KB |
Output is correct |
15 |
Correct |
201 ms |
35048 KB |
Output is correct |
16 |
Correct |
226 ms |
23900 KB |
Output is correct |
17 |
Correct |
304 ms |
23912 KB |
Output is correct |
18 |
Correct |
299 ms |
23912 KB |
Output is correct |
19 |
Correct |
206 ms |
35048 KB |
Output is correct |
20 |
Correct |
156 ms |
21612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
150 ms |
18768 KB |
Output is correct |
5 |
Correct |
164 ms |
18788 KB |
Output is correct |
6 |
Correct |
150 ms |
18788 KB |
Output is correct |
7 |
Correct |
144 ms |
18788 KB |
Output is correct |
8 |
Correct |
159 ms |
18788 KB |
Output is correct |
9 |
Correct |
155 ms |
18792 KB |
Output is correct |
10 |
Correct |
145 ms |
18788 KB |
Output is correct |
11 |
Correct |
147 ms |
18784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
352 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
11 ms |
1212 KB |
Output is correct |
6 |
Correct |
158 ms |
19304 KB |
Output is correct |
7 |
Correct |
161 ms |
19432 KB |
Output is correct |
8 |
Correct |
163 ms |
19340 KB |
Output is correct |
9 |
Correct |
172 ms |
19416 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
10 ms |
1212 KB |
Output is correct |
13 |
Correct |
11 ms |
1340 KB |
Output is correct |
14 |
Correct |
158 ms |
19408 KB |
Output is correct |
15 |
Correct |
159 ms |
19304 KB |
Output is correct |
16 |
Correct |
159 ms |
19428 KB |
Output is correct |
17 |
Correct |
150 ms |
19304 KB |
Output is correct |
18 |
Correct |
163 ms |
19528 KB |
Output is correct |
19 |
Correct |
171 ms |
19304 KB |
Output is correct |
20 |
Correct |
167 ms |
19304 KB |
Output is correct |
21 |
Correct |
172 ms |
19428 KB |
Output is correct |
22 |
Correct |
170 ms |
19304 KB |
Output is correct |
23 |
Correct |
163 ms |
19304 KB |
Output is correct |
24 |
Correct |
162 ms |
19300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
303 ms |
23828 KB |
Output is correct |
3 |
Correct |
305 ms |
23784 KB |
Output is correct |
4 |
Correct |
312 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 |
5 ms |
368 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 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 |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
504 KB |
Output is correct |
5 |
Correct |
70 ms |
6212 KB |
Output is correct |
6 |
Correct |
130 ms |
12012 KB |
Output is correct |
7 |
Correct |
211 ms |
18156 KB |
Output is correct |
8 |
Correct |
308 ms |
23908 KB |
Output is correct |
9 |
Correct |
300 ms |
23780 KB |
Output is correct |
10 |
Correct |
302 ms |
23784 KB |
Output is correct |
11 |
Correct |
5 ms |
400 KB |
Output is correct |
12 |
Correct |
300 ms |
23780 KB |
Output is correct |
13 |
Correct |
227 ms |
33480 KB |
Output is correct |
14 |
Correct |
246 ms |
23908 KB |
Output is correct |
15 |
Correct |
201 ms |
35048 KB |
Output is correct |
16 |
Correct |
226 ms |
23900 KB |
Output is correct |
17 |
Correct |
304 ms |
23912 KB |
Output is correct |
18 |
Correct |
299 ms |
23912 KB |
Output is correct |
19 |
Correct |
206 ms |
35048 KB |
Output is correct |
20 |
Correct |
156 ms |
21612 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
150 ms |
18768 KB |
Output is correct |
25 |
Correct |
164 ms |
18788 KB |
Output is correct |
26 |
Correct |
150 ms |
18788 KB |
Output is correct |
27 |
Correct |
144 ms |
18788 KB |
Output is correct |
28 |
Correct |
159 ms |
18788 KB |
Output is correct |
29 |
Correct |
155 ms |
18792 KB |
Output is correct |
30 |
Correct |
145 ms |
18788 KB |
Output is correct |
31 |
Correct |
147 ms |
18784 KB |
Output is correct |
32 |
Correct |
6 ms |
256 KB |
Output is correct |
33 |
Correct |
5 ms |
352 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
11 ms |
1212 KB |
Output is correct |
37 |
Correct |
158 ms |
19304 KB |
Output is correct |
38 |
Correct |
161 ms |
19432 KB |
Output is correct |
39 |
Correct |
163 ms |
19340 KB |
Output is correct |
40 |
Correct |
172 ms |
19416 KB |
Output is correct |
41 |
Correct |
5 ms |
376 KB |
Output is correct |
42 |
Correct |
5 ms |
504 KB |
Output is correct |
43 |
Correct |
10 ms |
1212 KB |
Output is correct |
44 |
Correct |
11 ms |
1340 KB |
Output is correct |
45 |
Correct |
158 ms |
19408 KB |
Output is correct |
46 |
Correct |
159 ms |
19304 KB |
Output is correct |
47 |
Correct |
159 ms |
19428 KB |
Output is correct |
48 |
Correct |
150 ms |
19304 KB |
Output is correct |
49 |
Correct |
163 ms |
19528 KB |
Output is correct |
50 |
Correct |
171 ms |
19304 KB |
Output is correct |
51 |
Correct |
167 ms |
19304 KB |
Output is correct |
52 |
Correct |
172 ms |
19428 KB |
Output is correct |
53 |
Correct |
170 ms |
19304 KB |
Output is correct |
54 |
Correct |
163 ms |
19304 KB |
Output is correct |
55 |
Correct |
162 ms |
19300 KB |
Output is correct |
56 |
Correct |
5 ms |
376 KB |
Output is correct |
57 |
Correct |
303 ms |
23828 KB |
Output is correct |
58 |
Correct |
305 ms |
23784 KB |
Output is correct |
59 |
Correct |
312 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 |
5 ms |
368 KB |
Output is correct |
63 |
Correct |
5 ms |
376 KB |
Output is correct |
64 |
Correct |
6 ms |
376 KB |
Output is correct |
65 |
Correct |
5 ms |
256 KB |
Output is correct |
66 |
Correct |
5 ms |
256 KB |
Output is correct |
67 |
Correct |
1 ms |
376 KB |
Output is correct |
68 |
Correct |
5 ms |
376 KB |
Output is correct |
69 |
Correct |
5 ms |
376 KB |
Output is correct |
70 |
Correct |
5 ms |
376 KB |
Output is correct |
71 |
Correct |
5 ms |
376 KB |
Output is correct |
72 |
Correct |
5 ms |
376 KB |
Output is correct |
73 |
Correct |
5 ms |
376 KB |
Output is correct |
74 |
Correct |
5 ms |
376 KB |
Output is correct |
75 |
Correct |
5 ms |
376 KB |
Output is correct |
76 |
Correct |
5 ms |
376 KB |
Output is correct |
77 |
Correct |
5 ms |
256 KB |
Output is correct |
78 |
Correct |
5 ms |
256 KB |
Output is correct |
79 |
Correct |
5 ms |
256 KB |
Output is correct |
80 |
Correct |
5 ms |
256 KB |
Output is correct |
81 |
Correct |
5 ms |
256 KB |
Output is correct |
82 |
Correct |
5 ms |
256 KB |
Output is correct |
83 |
Correct |
5 ms |
256 KB |
Output is correct |
84 |
Correct |
5 ms |
256 KB |
Output is correct |
85 |
Correct |
5 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 |
888 KB |
Output is correct |
89 |
Correct |
12 ms |
1148 KB |
Output is correct |
90 |
Correct |
13 ms |
1340 KB |
Output is correct |
91 |
Correct |
53 ms |
5692 KB |
Output is correct |
92 |
Correct |
111 ms |
11116 KB |
Output is correct |
93 |
Correct |
260 ms |
21864 KB |
Output is correct |
94 |
Correct |
261 ms |
21864 KB |
Output is correct |
95 |
Correct |
292 ms |
21860 KB |
Output is correct |
96 |
Correct |
271 ms |
21840 KB |
Output is correct |
97 |
Correct |
247 ms |
21456 KB |
Output is correct |
98 |
Correct |
246 ms |
21992 KB |
Output is correct |
99 |
Correct |
225 ms |
20708 KB |
Output is correct |
100 |
Correct |
260 ms |
21864 KB |
Output is correct |
101 |
Correct |
317 ms |
22428 KB |
Output is correct |
102 |
Correct |
186 ms |
20588 KB |
Output is correct |
103 |
Correct |
277 ms |
22752 KB |
Output is correct |
104 |
Correct |
291 ms |
23272 KB |
Output is correct |
105 |
Correct |
214 ms |
23780 KB |
Output is correct |
106 |
Correct |
167 ms |
20072 KB |
Output is correct |