# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
871090 |
2023-11-09T21:08:03 Z |
MinaRagy06 |
Paths (RMI21_paths) |
C++17 |
|
600 ms |
6928 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 100'005;
vector<array<int, 2>> adj[N];
int n, k;
int vals[N];
pair<ll, int> dfs(int i, int par, int parc) {
pair<ll, int> mx = {-1e18, 0};
for (auto [nxt, w] : adj[i]) {
if (nxt == par) continue;
mx = max(mx, dfs(nxt, i, w));
}
if (adj[i].size() == 1) {
vals[i] = parc;
return {parc, i};
}
vals[mx.second] += parc;
mx.first += parc;
return mx;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
for (int i = 1, u, v, w; i < n; i++) {
cin >> u >> v >> w;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
vals[j] = 0;
}
dfs(i, 0, 0);
sort(vals + 1, vals + n + 1);
reverse(vals + 1, vals + n + 1);
ll sum = 0;
for (int j = 1; j <= k; j++) {
sum += vals[j];
}
cout << sum << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1034 ms |
6928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |