#include "job.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mxN=2e5;
int n, dist[mxN];
vector<int> adj[mxN], p, u, d;
deque<int> q[mxN];
bool was[mxN];
ll ans=0;
void merge(int x, int y) {
d[x]+=d[y];
u[x]+=u[y];
}
void dfs(int x) {
for(int v:adj[x])
dfs(v), q[x].pb(v);
while(!q[x].empty()) {
int y=q[x].back();
if(d[y]*u[x]>d[x]*u[y])
break;
was[y]=true;
q[x].pop_front();
ans-=d[y]*u[x];
merge(x, y);
if((int)q[x].size()<(int)q[y].size())
swap(q[x], q[y]);
while(!q[y].size())
q[x].pb(q[y].back()), q[y].pop_back();
}
}
ll scheduling_cost(vector<int> p1, vector<int> u1, vector<int> d1) {
p=p1, u=u1, d=d1;
n = (int) p.size();
for(int i=1; i<n; ++i)
adj[p1[i]].pb(i);
dfs(0);
vector<int> j;
for(int i=0; i<n; ++i)
if(!was[i])
j.pb(i);
sort(j.rbegin(), j.rend(), [&](int x, int y) {
return d[x]*u[y]>d[y]*u[x];
});
ll t=0;
for(int i:j)
t+=d[i], ans+=u[i]*t;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
271 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
274 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
267 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
274 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
265 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
271 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |