# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
848668 | 2023-09-13T08:36:23 Z | TahirAliyev | Paths (RMI21_paths) | C++17 | 1 ms | 604 KB |
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long int #define oo 1e9 #define pii pair<ll, int> const int MAX = 2002; int n, k; vector<pii> g[MAX]; vector<ll> val; int heavy[MAX]; int dfs(int node, int p){ pii m = {0, 0}; for(pii to : g[node]){ if(p == to.first) continue; int a = dfs(to.first, node) + to.second; if(m.first < a){ m = {a, to.first}; } } heavy[node] = m.second; return m.first; } void dfs2(int node, int p, int h){ if(g[node].size() == 1 && p != node){ val.push_back(h); return; } for(pii to : g[node]){ if(p == to.first) continue; if(heavy[node] == to.first){ dfs2(heavy[node], node, h + to.second); } else{ dfs2(to.first, node, to.second); } } } int main(){ scanf("%d%d", &n, &k); for(int i = 1; i < n; i++){ int u, v, a; scanf("%d%d%d", &u, &v, &a); g[u].push_back({v, a}); g[v].push_back({u, a}); } for(int i = 1; i <= n; i++){ val.clear(); memset(heavy, 0, sizeof(heavy)); dfs(i, i); dfs2(i, i, 0); sort(val.begin(), val.end()); ll ans = 0; for(int i = val.size() - 1; i >= max(int(val.size() - k), 0); i--){ ans += val[i]; } cout << ans << '\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 604 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |