#include "deliveries.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
typedef long long llong;
const int MAXN = 100000 + 10;
const int INF = 1e9;
int n;
int w[MAXN];
llong sz[MAXN], sum;
std::vector <std::pair <int,int>> g[MAXN];
void init(int N, std::vector<int> U, std::vector<int> V, std::vector<int> T, std::vector<int> W)
{
n = N;
for (int i = 0 ; i < n - 1 ; ++i)
{
g[U[i]].push_back({V[i], T[i]});
g[V[i]].push_back({U[i], T[i]});
}
for (int i = 0 ; i < n ; ++i)
{
w[i] = W[i];
sum += w[i];
}
w[0]++;
sum++;
}
void fixDFS(int node, int par)
{
sz[node] = w[node];
for (const auto &[u, d] : g[node])
{
if (u == par)
{
continue;
}
fixDFS(u, node);
sz[node] += sz[u];
}
}
int findDFS(int node, int par)
{
for (const auto &[u, d] : g[node])
{
if (u == par)
{
continue;
}
if (sz[u] > sum / 2)
{
return findDFS(u, node);
}
}
return node;
}
llong calcDFS(int node, int par, llong currD)
{
llong res = currD * w[node];
for (const auto &[u, d] : g[node])
{
if (u == par)
{
continue;
}
res += calcDFS(u, node, currD + d);
}
return res;
}
long long max_time(int S, int X)
{
sum -= w[S];
w[S] = X;
if (S == 0) w[S]++;
sum += w[S];
fixDFS(0, -1);
return 2 * calcDFS(findDFS(0, -1), -1, 0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
10364 KB |
Output is correct |
2 |
Correct |
75 ms |
9872 KB |
Output is correct |
3 |
Correct |
75 ms |
10100 KB |
Output is correct |
4 |
Correct |
75 ms |
10064 KB |
Output is correct |
5 |
Correct |
78 ms |
10272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
9 ms |
2868 KB |
Output is correct |
3 |
Correct |
13 ms |
2908 KB |
Output is correct |
4 |
Correct |
15 ms |
2648 KB |
Output is correct |
5 |
Correct |
16 ms |
2908 KB |
Output is correct |
6 |
Correct |
16 ms |
2908 KB |
Output is correct |
7 |
Correct |
15 ms |
2908 KB |
Output is correct |
8 |
Correct |
15 ms |
2908 KB |
Output is correct |
9 |
Correct |
16 ms |
2908 KB |
Output is correct |
10 |
Correct |
17 ms |
2932 KB |
Output is correct |
11 |
Correct |
10 ms |
2652 KB |
Output is correct |
12 |
Correct |
12 ms |
2652 KB |
Output is correct |
13 |
Correct |
13 ms |
2876 KB |
Output is correct |
14 |
Correct |
22 ms |
2912 KB |
Output is correct |
15 |
Correct |
22 ms |
2896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
10364 KB |
Output is correct |
2 |
Correct |
75 ms |
9872 KB |
Output is correct |
3 |
Correct |
75 ms |
10100 KB |
Output is correct |
4 |
Correct |
75 ms |
10064 KB |
Output is correct |
5 |
Correct |
78 ms |
10272 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
30 ms |
2916 KB |
Output is correct |
8 |
Correct |
2937 ms |
4336 KB |
Output is correct |
9 |
Execution timed out |
5521 ms |
14132 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
10364 KB |
Output is correct |
2 |
Correct |
75 ms |
9872 KB |
Output is correct |
3 |
Correct |
75 ms |
10100 KB |
Output is correct |
4 |
Correct |
75 ms |
10064 KB |
Output is correct |
5 |
Correct |
78 ms |
10272 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
49 ms |
2964 KB |
Output is correct |
8 |
Correct |
5043 ms |
4876 KB |
Output is correct |
9 |
Execution timed out |
5517 ms |
19764 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
10364 KB |
Output is correct |
2 |
Correct |
75 ms |
9872 KB |
Output is correct |
3 |
Correct |
75 ms |
10100 KB |
Output is correct |
4 |
Correct |
75 ms |
10064 KB |
Output is correct |
5 |
Correct |
78 ms |
10272 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
9 ms |
2868 KB |
Output is correct |
8 |
Correct |
13 ms |
2908 KB |
Output is correct |
9 |
Correct |
15 ms |
2648 KB |
Output is correct |
10 |
Correct |
16 ms |
2908 KB |
Output is correct |
11 |
Correct |
16 ms |
2908 KB |
Output is correct |
12 |
Correct |
15 ms |
2908 KB |
Output is correct |
13 |
Correct |
15 ms |
2908 KB |
Output is correct |
14 |
Correct |
16 ms |
2908 KB |
Output is correct |
15 |
Correct |
17 ms |
2932 KB |
Output is correct |
16 |
Correct |
10 ms |
2652 KB |
Output is correct |
17 |
Correct |
12 ms |
2652 KB |
Output is correct |
18 |
Correct |
13 ms |
2876 KB |
Output is correct |
19 |
Correct |
22 ms |
2912 KB |
Output is correct |
20 |
Correct |
22 ms |
2896 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
30 ms |
2916 KB |
Output is correct |
23 |
Correct |
2937 ms |
4336 KB |
Output is correct |
24 |
Execution timed out |
5521 ms |
14132 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |