#include "job.h"
#include <vector>
#include <algorithm>
//#include <iostream>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long llong;
int N;
VVI tree;
VI D, U;
vector<llong> sumD, sumU;
void dfs(int x) {
sumD[x] = D[x];
sumU[x] = U[x];
for (int y : tree[x]) {
dfs(y);
sumD[x] += sumD[y];
sumU[x] += sumD[y];
}
}
llong dfs2(int x, llong T) {
T += D[x];
llong res = U[x] * T;
sort(tree[x].begin(), tree[x].end(),
[&] (int i, int j) -> bool {
return sumD[i] * sumU[j] < sumD[j] * sumU[i];
});
for (int y : tree[x]) {
res += dfs2(y, T);
T += sumD[y];
}
return res;
}
long long scheduling_cost(vector<int> p, vector<int> u, vector<int> d) {
N = p.size();
tree = VVI(N);
::D = d;
::U = u;
for (int i = 1; i < N; ++i)
tree[ p[i] ].push_back(i);
sumD.assign(N, 0);
sumU.assign(N, 0);
dfs(0);
// for (int x = 0; x < N; ++x)
// cerr << x << ": " << sumD[x] << ' ' << sumU[x] << endl;
llong res = dfs2(0, 0);
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
28 ms |
10112 KB |
Output is correct |
6 |
Correct |
53 ms |
19832 KB |
Output is correct |
7 |
Correct |
83 ms |
29692 KB |
Output is correct |
8 |
Correct |
127 ms |
39548 KB |
Output is correct |
9 |
Correct |
107 ms |
39548 KB |
Output is correct |
10 |
Correct |
101 ms |
39544 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
110 ms |
39544 KB |
Output is correct |
13 |
Correct |
106 ms |
39544 KB |
Output is correct |
14 |
Correct |
109 ms |
39544 KB |
Output is correct |
15 |
Correct |
106 ms |
39544 KB |
Output is correct |
16 |
Correct |
108 ms |
39548 KB |
Output is correct |
17 |
Correct |
100 ms |
39544 KB |
Output is correct |
18 |
Correct |
99 ms |
39544 KB |
Output is correct |
19 |
Correct |
103 ms |
39544 KB |
Output is correct |
20 |
Correct |
117 ms |
39544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
99 ms |
17132 KB |
Output is correct |
5 |
Correct |
102 ms |
17132 KB |
Output is correct |
6 |
Correct |
104 ms |
17260 KB |
Output is correct |
7 |
Correct |
123 ms |
17260 KB |
Output is correct |
8 |
Correct |
108 ms |
17132 KB |
Output is correct |
9 |
Correct |
108 ms |
17260 KB |
Output is correct |
10 |
Correct |
96 ms |
17132 KB |
Output is correct |
11 |
Correct |
100 ms |
17132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
6 |
Correct |
114 ms |
17668 KB |
Output is correct |
7 |
Correct |
105 ms |
17644 KB |
Output is correct |
8 |
Correct |
105 ms |
17644 KB |
Output is correct |
9 |
Correct |
109 ms |
17644 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
1280 KB |
Output is correct |
13 |
Correct |
5 ms |
1280 KB |
Output is correct |
14 |
Correct |
119 ms |
17776 KB |
Output is correct |
15 |
Correct |
114 ms |
17656 KB |
Output is correct |
16 |
Correct |
111 ms |
17644 KB |
Output is correct |
17 |
Correct |
113 ms |
17752 KB |
Output is correct |
18 |
Correct |
130 ms |
17644 KB |
Output is correct |
19 |
Correct |
110 ms |
17644 KB |
Output is correct |
20 |
Correct |
107 ms |
17648 KB |
Output is correct |
21 |
Correct |
108 ms |
17772 KB |
Output is correct |
22 |
Correct |
121 ms |
17736 KB |
Output is correct |
23 |
Correct |
109 ms |
17772 KB |
Output is correct |
24 |
Correct |
121 ms |
17644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
28 ms |
10112 KB |
Output is correct |
6 |
Correct |
53 ms |
19832 KB |
Output is correct |
7 |
Correct |
83 ms |
29692 KB |
Output is correct |
8 |
Correct |
127 ms |
39548 KB |
Output is correct |
9 |
Correct |
107 ms |
39548 KB |
Output is correct |
10 |
Correct |
101 ms |
39544 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
110 ms |
39544 KB |
Output is correct |
13 |
Correct |
106 ms |
39544 KB |
Output is correct |
14 |
Correct |
109 ms |
39544 KB |
Output is correct |
15 |
Correct |
106 ms |
39544 KB |
Output is correct |
16 |
Correct |
108 ms |
39548 KB |
Output is correct |
17 |
Correct |
100 ms |
39544 KB |
Output is correct |
18 |
Correct |
99 ms |
39544 KB |
Output is correct |
19 |
Correct |
103 ms |
39544 KB |
Output is correct |
20 |
Correct |
117 ms |
39544 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
0 ms |
256 KB |
Output is correct |
23 |
Correct |
0 ms |
256 KB |
Output is correct |
24 |
Correct |
99 ms |
17132 KB |
Output is correct |
25 |
Correct |
102 ms |
17132 KB |
Output is correct |
26 |
Correct |
104 ms |
17260 KB |
Output is correct |
27 |
Correct |
123 ms |
17260 KB |
Output is correct |
28 |
Correct |
108 ms |
17132 KB |
Output is correct |
29 |
Correct |
108 ms |
17260 KB |
Output is correct |
30 |
Correct |
96 ms |
17132 KB |
Output is correct |
31 |
Correct |
100 ms |
17132 KB |
Output is correct |
32 |
Correct |
0 ms |
256 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
0 ms |
256 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
1280 KB |
Output is correct |
37 |
Correct |
114 ms |
17668 KB |
Output is correct |
38 |
Correct |
105 ms |
17644 KB |
Output is correct |
39 |
Correct |
105 ms |
17644 KB |
Output is correct |
40 |
Correct |
109 ms |
17644 KB |
Output is correct |
41 |
Correct |
1 ms |
256 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
7 ms |
1280 KB |
Output is correct |
44 |
Correct |
5 ms |
1280 KB |
Output is correct |
45 |
Correct |
119 ms |
17776 KB |
Output is correct |
46 |
Correct |
114 ms |
17656 KB |
Output is correct |
47 |
Correct |
111 ms |
17644 KB |
Output is correct |
48 |
Correct |
113 ms |
17752 KB |
Output is correct |
49 |
Correct |
130 ms |
17644 KB |
Output is correct |
50 |
Correct |
110 ms |
17644 KB |
Output is correct |
51 |
Correct |
107 ms |
17648 KB |
Output is correct |
52 |
Correct |
108 ms |
17772 KB |
Output is correct |
53 |
Correct |
121 ms |
17736 KB |
Output is correct |
54 |
Correct |
109 ms |
17772 KB |
Output is correct |
55 |
Correct |
121 ms |
17644 KB |
Output is correct |
56 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
57 |
Halted |
0 ms |
0 KB |
- |