#include "roads.h"
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_map>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>
using namespace std;
using ll = long long;
vector<vector<pair<int, int>>> gp;
vector<vector<ll>> dp;
void dfs(int u, int p, int k) {
vector<ll> vec;
for (pair<int, int>& v : gp[u]) {
if (v.first == p) continue;
dfs(v.first, u, k);
dp[u][k] += dp[v.first][k - 1];
vec.push_back(max(0ll, dp[v.first][k - 1] + v.second - dp[v.first][k]));
}
//dp[u][0] =
sort(vec.rbegin(), vec.rend());
for (int i = 0; i < min(int(vec.size()), k); ++i) dp[u][k] += vec[i];
}
vector<ll> minimum_closure_costs(int n, vector<int> U,vector<int> V,vector<int> W) {
gp = vector<vector<pair<int, int>>>(n);
dp = vector<vector<ll>>(n, vector<ll>(n));
ll sm = 0;
for (int i = 0; i < n - 1; ++i) {
gp[U[i]].push_back({ V[i], W[i] });
gp[V[i]].push_back({ U[i], W[i] });
sm += W[i];
}
vector<ll> vec(n);
vec[0] = sm;
for (int i = 1; i < n; ++i) {
dfs(0, -1, i);
vec[i] = sm - dp[0][i];
}
return vec;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
200 ms |
28276 KB |
Output is correct |
3 |
Correct |
260 ms |
31920 KB |
Output is correct |
4 |
Correct |
124 ms |
31932 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
103 ms |
22764 KB |
Output is correct |
9 |
Correct |
166 ms |
31828 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Runtime error |
545 ms |
1048576 KB |
Execution killed with signal 9 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
425 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
528 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
528 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
200 ms |
28276 KB |
Output is correct |
3 |
Correct |
260 ms |
31920 KB |
Output is correct |
4 |
Correct |
124 ms |
31932 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
103 ms |
22764 KB |
Output is correct |
9 |
Correct |
166 ms |
31828 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Runtime error |
545 ms |
1048576 KB |
Execution killed with signal 9 |
13 |
Halted |
0 ms |
0 KB |
- |