/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
#include "job.h"
using namespace std;
typedef long long ll;
const int N_MAX = 200002;
int n;
struct Cost
{
int d, u;
};
Cost cost[N_MAX];
int parent[N_MAX];
vector <int> sons[N_MAX];
bool operator < (const Cost &a, const Cost &b)
{
return (ll)a.d * b.u < (ll)b.d * a.u;
}
struct Node
{
int u;
Cost c;
};
bool operator < (const Node &u, const Node &v)
{
return make_pair(u.c, u.u) < make_pair(v.c, v.u);
}
ll answer = 0;
set <Node> notJoined[N_MAX];
void mergeSets (int u, int v)
{
answer += (ll)cost[u].d * cost[v].u;
cost[u].d += cost[v].d;
cost[u].u += cost[v].u;
set <Node> &in = notJoined[u];
set <Node> &from = notJoined[v];
if(in.size() < from.size())
swap(in, from);
while(from.empty() == false)
{
in.insert(*from.begin());
from.erase(from.begin());
}
}
void dfs (int u)
{
for(int v : sons[u])
{
dfs(v);
notJoined[u].insert(Node{v, cost[v]});
}
while (!notJoined[u].empty())
{
int v = notJoined[u].begin()->u;
if(cost[u] < cost[v])
break;
notJoined[u].erase(notJoined[u].begin());
mergeSets(u, v);
}
}
int order[N_MAX];
int curr;
ll scheduling_cost (vector <int> p, vector <int> u, vector <int> d)
{
n = p.size();
for(int i = 1; i <= n; i++)
{
parent[i] = p[i - 1] + 1;
cost[i] = Cost{d[i - 1], u[i - 1]};
answer += (ll)cost[i].u * cost[i].d;
}
for(int i = 2; i <= n; i++)
sons[parent[i]].push_back(i);
dfs(1);
while(!notJoined[1].empty())
{
int v = notJoined[1].begin()->u;
notJoined[1].erase(notJoined[1].begin());
mergeSets(1, v);
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14700 KB |
Output is correct |
5 |
Correct |
39 ms |
25572 KB |
Output is correct |
6 |
Correct |
69 ms |
36708 KB |
Output is correct |
7 |
Correct |
97 ms |
47952 KB |
Output is correct |
8 |
Correct |
127 ms |
59108 KB |
Output is correct |
9 |
Correct |
129 ms |
59108 KB |
Output is correct |
10 |
Correct |
128 ms |
59168 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
127 ms |
59108 KB |
Output is correct |
13 |
Correct |
121 ms |
59108 KB |
Output is correct |
14 |
Correct |
124 ms |
59108 KB |
Output is correct |
15 |
Correct |
119 ms |
59032 KB |
Output is correct |
16 |
Correct |
159 ms |
59364 KB |
Output is correct |
17 |
Correct |
134 ms |
59236 KB |
Output is correct |
18 |
Correct |
129 ms |
59108 KB |
Output is correct |
19 |
Correct |
125 ms |
59108 KB |
Output is correct |
20 |
Correct |
133 ms |
67684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
261 ms |
36696 KB |
Output is correct |
5 |
Correct |
252 ms |
36568 KB |
Output is correct |
6 |
Correct |
251 ms |
36568 KB |
Output is correct |
7 |
Correct |
264 ms |
36636 KB |
Output is correct |
8 |
Correct |
257 ms |
36568 KB |
Output is correct |
9 |
Correct |
268 ms |
36496 KB |
Output is correct |
10 |
Correct |
255 ms |
36568 KB |
Output is correct |
11 |
Correct |
253 ms |
36568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14572 KB |
Output is correct |
5 |
Correct |
18 ms |
15596 KB |
Output is correct |
6 |
Correct |
270 ms |
37092 KB |
Output is correct |
7 |
Correct |
259 ms |
37080 KB |
Output is correct |
8 |
Correct |
251 ms |
37080 KB |
Output is correct |
9 |
Correct |
257 ms |
37080 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
11 ms |
14572 KB |
Output is correct |
12 |
Correct |
16 ms |
15468 KB |
Output is correct |
13 |
Correct |
17 ms |
15596 KB |
Output is correct |
14 |
Correct |
282 ms |
37080 KB |
Output is correct |
15 |
Correct |
251 ms |
37080 KB |
Output is correct |
16 |
Correct |
257 ms |
37080 KB |
Output is correct |
17 |
Correct |
248 ms |
37080 KB |
Output is correct |
18 |
Correct |
264 ms |
37080 KB |
Output is correct |
19 |
Correct |
262 ms |
37080 KB |
Output is correct |
20 |
Correct |
257 ms |
37080 KB |
Output is correct |
21 |
Correct |
255 ms |
37080 KB |
Output is correct |
22 |
Correct |
257 ms |
37208 KB |
Output is correct |
23 |
Correct |
253 ms |
37080 KB |
Output is correct |
24 |
Correct |
252 ms |
37208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14476 KB |
Output is correct |
2 |
Correct |
147 ms |
45156 KB |
Output is correct |
3 |
Correct |
120 ms |
45028 KB |
Output is correct |
4 |
Correct |
121 ms |
45028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
11 ms |
14444 KB |
Output is correct |
7 |
Correct |
10 ms |
14444 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
11 ms |
14444 KB |
Output is correct |
10 |
Correct |
10 ms |
14444 KB |
Output is correct |
11 |
Correct |
10 ms |
14572 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
11 ms |
14444 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
11 ms |
14444 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
10 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14700 KB |
Output is correct |
5 |
Correct |
39 ms |
25572 KB |
Output is correct |
6 |
Correct |
69 ms |
36708 KB |
Output is correct |
7 |
Correct |
97 ms |
47952 KB |
Output is correct |
8 |
Correct |
127 ms |
59108 KB |
Output is correct |
9 |
Correct |
129 ms |
59108 KB |
Output is correct |
10 |
Correct |
128 ms |
59168 KB |
Output is correct |
11 |
Correct |
10 ms |
14444 KB |
Output is correct |
12 |
Correct |
127 ms |
59108 KB |
Output is correct |
13 |
Correct |
121 ms |
59108 KB |
Output is correct |
14 |
Correct |
124 ms |
59108 KB |
Output is correct |
15 |
Correct |
119 ms |
59032 KB |
Output is correct |
16 |
Correct |
159 ms |
59364 KB |
Output is correct |
17 |
Correct |
134 ms |
59236 KB |
Output is correct |
18 |
Correct |
129 ms |
59108 KB |
Output is correct |
19 |
Correct |
125 ms |
59108 KB |
Output is correct |
20 |
Correct |
133 ms |
67684 KB |
Output is correct |
21 |
Correct |
10 ms |
14444 KB |
Output is correct |
22 |
Correct |
10 ms |
14444 KB |
Output is correct |
23 |
Correct |
10 ms |
14444 KB |
Output is correct |
24 |
Correct |
261 ms |
36696 KB |
Output is correct |
25 |
Correct |
252 ms |
36568 KB |
Output is correct |
26 |
Correct |
251 ms |
36568 KB |
Output is correct |
27 |
Correct |
264 ms |
36636 KB |
Output is correct |
28 |
Correct |
257 ms |
36568 KB |
Output is correct |
29 |
Correct |
268 ms |
36496 KB |
Output is correct |
30 |
Correct |
255 ms |
36568 KB |
Output is correct |
31 |
Correct |
253 ms |
36568 KB |
Output is correct |
32 |
Correct |
11 ms |
14444 KB |
Output is correct |
33 |
Correct |
10 ms |
14444 KB |
Output is correct |
34 |
Correct |
10 ms |
14444 KB |
Output is correct |
35 |
Correct |
10 ms |
14572 KB |
Output is correct |
36 |
Correct |
18 ms |
15596 KB |
Output is correct |
37 |
Correct |
270 ms |
37092 KB |
Output is correct |
38 |
Correct |
259 ms |
37080 KB |
Output is correct |
39 |
Correct |
251 ms |
37080 KB |
Output is correct |
40 |
Correct |
257 ms |
37080 KB |
Output is correct |
41 |
Correct |
10 ms |
14444 KB |
Output is correct |
42 |
Correct |
11 ms |
14572 KB |
Output is correct |
43 |
Correct |
16 ms |
15468 KB |
Output is correct |
44 |
Correct |
17 ms |
15596 KB |
Output is correct |
45 |
Correct |
282 ms |
37080 KB |
Output is correct |
46 |
Correct |
251 ms |
37080 KB |
Output is correct |
47 |
Correct |
257 ms |
37080 KB |
Output is correct |
48 |
Correct |
248 ms |
37080 KB |
Output is correct |
49 |
Correct |
264 ms |
37080 KB |
Output is correct |
50 |
Correct |
262 ms |
37080 KB |
Output is correct |
51 |
Correct |
257 ms |
37080 KB |
Output is correct |
52 |
Correct |
255 ms |
37080 KB |
Output is correct |
53 |
Correct |
257 ms |
37208 KB |
Output is correct |
54 |
Correct |
253 ms |
37080 KB |
Output is correct |
55 |
Correct |
252 ms |
37208 KB |
Output is correct |
56 |
Correct |
10 ms |
14476 KB |
Output is correct |
57 |
Correct |
147 ms |
45156 KB |
Output is correct |
58 |
Correct |
120 ms |
45028 KB |
Output is correct |
59 |
Correct |
121 ms |
45028 KB |
Output is correct |
60 |
Correct |
10 ms |
14464 KB |
Output is correct |
61 |
Correct |
10 ms |
14444 KB |
Output is correct |
62 |
Correct |
10 ms |
14444 KB |
Output is correct |
63 |
Correct |
10 ms |
14444 KB |
Output is correct |
64 |
Correct |
10 ms |
14444 KB |
Output is correct |
65 |
Correct |
11 ms |
14444 KB |
Output is correct |
66 |
Correct |
10 ms |
14444 KB |
Output is correct |
67 |
Correct |
10 ms |
14444 KB |
Output is correct |
68 |
Correct |
11 ms |
14444 KB |
Output is correct |
69 |
Correct |
10 ms |
14444 KB |
Output is correct |
70 |
Correct |
10 ms |
14572 KB |
Output is correct |
71 |
Correct |
10 ms |
14444 KB |
Output is correct |
72 |
Correct |
11 ms |
14444 KB |
Output is correct |
73 |
Correct |
10 ms |
14444 KB |
Output is correct |
74 |
Correct |
10 ms |
14444 KB |
Output is correct |
75 |
Correct |
11 ms |
14444 KB |
Output is correct |
76 |
Correct |
10 ms |
14444 KB |
Output is correct |
77 |
Correct |
10 ms |
14444 KB |
Output is correct |
78 |
Correct |
10 ms |
14444 KB |
Output is correct |
79 |
Correct |
10 ms |
14464 KB |
Output is correct |
80 |
Correct |
10 ms |
14444 KB |
Output is correct |
81 |
Correct |
10 ms |
14444 KB |
Output is correct |
82 |
Correct |
10 ms |
14444 KB |
Output is correct |
83 |
Correct |
10 ms |
14444 KB |
Output is correct |
84 |
Correct |
10 ms |
14444 KB |
Output is correct |
85 |
Correct |
11 ms |
14444 KB |
Output is correct |
86 |
Correct |
10 ms |
14444 KB |
Output is correct |
87 |
Correct |
10 ms |
14572 KB |
Output is correct |
88 |
Correct |
14 ms |
14956 KB |
Output is correct |
89 |
Correct |
16 ms |
15212 KB |
Output is correct |
90 |
Correct |
19 ms |
15468 KB |
Output is correct |
91 |
Correct |
55 ms |
19428 KB |
Output is correct |
92 |
Correct |
115 ms |
24292 KB |
Output is correct |
93 |
Correct |
260 ms |
34276 KB |
Output is correct |
94 |
Correct |
266 ms |
34148 KB |
Output is correct |
95 |
Correct |
258 ms |
34148 KB |
Output is correct |
96 |
Correct |
259 ms |
34276 KB |
Output is correct |
97 |
Correct |
255 ms |
34020 KB |
Output is correct |
98 |
Correct |
234 ms |
35432 KB |
Output is correct |
99 |
Correct |
291 ms |
36292 KB |
Output is correct |
100 |
Correct |
261 ms |
34276 KB |
Output is correct |
101 |
Correct |
215 ms |
32996 KB |
Output is correct |
102 |
Correct |
313 ms |
40548 KB |
Output is correct |
103 |
Correct |
212 ms |
31972 KB |
Output is correct |
104 |
Correct |
204 ms |
31076 KB |
Output is correct |
105 |
Correct |
155 ms |
31716 KB |
Output is correct |
106 |
Correct |
296 ms |
37732 KB |
Output is correct |