# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
711857 | onjo0127 | Job Scheduling (IOI19_job) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}