# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
711857 | onjo0127 | Job Scheduling (IOI19_job) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using pli = pair<long long, int>;
const long long INF = 1LL * 1e18;
int P[200009], pa[200009];
long long A[200009], B[200009], T[200009];
bool chk[200009];
struct info { int v; };
bool operator <(info p, info q) {
return (pli){A[q.v] * T[p.v], p.v} < (pli){A[p.v] * T[q.v], q.v};
}
int root(int x) {
if(pa[x] == x) return x;
return pa[x] = root(pa[x]);
}
int main() {
int N; scanf("%d",&N);
for(int i=1; i<=N; i++) {
int d, t; scanf("%d%d%d", &P[i], &d, &t);
A[i] = d, B[i] = d*t, T[i] = t;
pa[i] = i;
}
set<info> st;
for(int i=2; i<=N; i++) st.insert({i});
while(st.size()) {
int x = (*st.begin()).v; st.erase(st.begin());
pa[x] = P[x] = root(P[x]);
if(P[x] != 1) st.erase({P[x]});
B[P[x]] += B[x] + A[x]*T[P[x]];
A[P[x]] += A[x];
T[P[x]] += T[x];
if(P[x] != 1) st.insert({P[x]});
}
printf("%lld", B[1]);
return 0;
}