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 "job.h"
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;
ll n;
vector<ll> g[200009];
ll root;
ll ans = 0;
void spsort(vector<pii> &vec){
ll cnt = vec.size();
while(cnt--){
for(ll i = 0; i < vec.size()-1; ++i){
if(vec[i+1].ff*vec[i].ss > vec[i].ff*vec[i+1].ss)
swap(vec[i], vec[i+1]);
}
}
}
pii dfs(ll v, ll curt, vector<int> &c, vector<int> &t){
curt += t[v];
ans += c[v]*curt;
//cout << v << ' ' << c[v] << ' ' << curt << '\n';
vector<pii> vec;
for(auto u : g[v])
vec.pb(dfs(u, curt, c, t));
spsort(vec);
pii ret = {0, 0};
for(auto u : vec){
ans += u.ff*ret.ss;
ret.ss += u.ss;
ret.ff += u.ff;
}
ret.ss += t[v];
ret.ff += c[v];
return ret;
}
long long scheduling_cost(std::vector<int> p, std::vector<int> u, std::vector<int> d) {
n = p.size();
for(ll i = 0; i < n; ++i){
if(p[i] == -1)
root = i;
else
g[p[i]].pb(i);
}
ans = 0;
dfs(root, 0, u, d);
return ans;
}
Compilation message (stderr)
job.cpp: In function 'void spsort(std::vector<std::pair<long long int, long long int> >&)':
job.cpp:19:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(ll i = 0; i < vec.size()-1; ++i){
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |