#include "job.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define all(x) x.begin(), x.end()
#define ii pair<int, int>
#define f first
#define s second
#define mp make_pair
ll ans = 0;
vector<int> adj[200000];
vector<int> p, u, d;
vector<pair<int, pair<ll,ll>>> indices;
bool done[200000];
void dfs(int node, ll dist, ll sumU) {
//ans += d[node]*dist;
indices.pb(mp(node, mp(dist, sumU)));
for (int v : adj[node]) {
dfs(v, dist+d[v], sumU + u[v]);
}
}
long long scheduling_cost(std::vector<int> _p, std::vector<int> _u, std::vector<int> _d) {
p = _p, u = _u, d = _d;
int n = p.size();
for (int i = 1; i < n; i++) {
adj[p[i]].pb(i);
}
dfs(0, d[0], u[0]);
ll curTime = 0;
sort(all(indices), [](pair<int, pair<ll,ll>> x, pair<int, pair<ll,ll>> y) {
return x.s.f*y.s.s<x.s.s*y.s.f;
});
for (auto x : indices) {
vector<int> todo;
int node = x.f;
while (node != -1 && !done[node]) {
todo.pb(node);
done[node] = true;
node = p[node];
}
reverse(all(todo));
for (auto node : todo) {
curTime += d[node];
ans += curTime*u[node];
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
4972 KB |
Output is correct |
3 |
Correct |
4 ms |
4972 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
34 ms |
15200 KB |
Output is correct |
6 |
Correct |
69 ms |
25952 KB |
Output is correct |
7 |
Correct |
97 ms |
35932 KB |
Output is correct |
8 |
Correct |
125 ms |
46172 KB |
Output is correct |
9 |
Correct |
124 ms |
45652 KB |
Output is correct |
10 |
Correct |
132 ms |
46056 KB |
Output is correct |
11 |
Correct |
4 ms |
4992 KB |
Output is correct |
12 |
Correct |
128 ms |
45776 KB |
Output is correct |
13 |
Correct |
121 ms |
47192 KB |
Output is correct |
14 |
Correct |
122 ms |
45520 KB |
Output is correct |
15 |
Correct |
115 ms |
47064 KB |
Output is correct |
16 |
Correct |
118 ms |
45528 KB |
Output is correct |
17 |
Correct |
133 ms |
46928 KB |
Output is correct |
18 |
Correct |
127 ms |
46032 KB |
Output is correct |
19 |
Correct |
115 ms |
47064 KB |
Output is correct |
20 |
Correct |
117 ms |
45400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
3 ms |
4972 KB |
Output is correct |
4 |
Correct |
106 ms |
19812 KB |
Output is correct |
5 |
Correct |
105 ms |
19800 KB |
Output is correct |
6 |
Correct |
105 ms |
19820 KB |
Output is correct |
7 |
Correct |
105 ms |
19800 KB |
Output is correct |
8 |
Correct |
105 ms |
19800 KB |
Output is correct |
9 |
Correct |
105 ms |
19800 KB |
Output is correct |
10 |
Correct |
106 ms |
19800 KB |
Output is correct |
11 |
Correct |
105 ms |
19800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4972 KB |
Output is correct |
2 |
Incorrect |
126 ms |
37212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4972 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4972 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
4972 KB |
Output is correct |
3 |
Correct |
4 ms |
4972 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
34 ms |
15200 KB |
Output is correct |
6 |
Correct |
69 ms |
25952 KB |
Output is correct |
7 |
Correct |
97 ms |
35932 KB |
Output is correct |
8 |
Correct |
125 ms |
46172 KB |
Output is correct |
9 |
Correct |
124 ms |
45652 KB |
Output is correct |
10 |
Correct |
132 ms |
46056 KB |
Output is correct |
11 |
Correct |
4 ms |
4992 KB |
Output is correct |
12 |
Correct |
128 ms |
45776 KB |
Output is correct |
13 |
Correct |
121 ms |
47192 KB |
Output is correct |
14 |
Correct |
122 ms |
45520 KB |
Output is correct |
15 |
Correct |
115 ms |
47064 KB |
Output is correct |
16 |
Correct |
118 ms |
45528 KB |
Output is correct |
17 |
Correct |
133 ms |
46928 KB |
Output is correct |
18 |
Correct |
127 ms |
46032 KB |
Output is correct |
19 |
Correct |
115 ms |
47064 KB |
Output is correct |
20 |
Correct |
117 ms |
45400 KB |
Output is correct |
21 |
Correct |
3 ms |
4992 KB |
Output is correct |
22 |
Correct |
4 ms |
5100 KB |
Output is correct |
23 |
Correct |
3 ms |
4972 KB |
Output is correct |
24 |
Correct |
106 ms |
19812 KB |
Output is correct |
25 |
Correct |
105 ms |
19800 KB |
Output is correct |
26 |
Correct |
105 ms |
19820 KB |
Output is correct |
27 |
Correct |
105 ms |
19800 KB |
Output is correct |
28 |
Correct |
105 ms |
19800 KB |
Output is correct |
29 |
Correct |
105 ms |
19800 KB |
Output is correct |
30 |
Correct |
106 ms |
19800 KB |
Output is correct |
31 |
Correct |
105 ms |
19800 KB |
Output is correct |
32 |
Incorrect |
3 ms |
4972 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |