Submission #871080

#TimeUsernameProblemLanguageResultExecution timeMemory
871080MinaRagy06Paths (RMI21_paths)C++17
19 / 100
1041 ms277096 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 100'005; multiset<ll> s[N]; vector<array<int, 2>> adj[N]; void dfs(int i, int par, int parc) { for (auto [nxt, w] : adj[i]) { if (nxt == par) continue; dfs(nxt, i, w); if (s[i] < s[nxt]) { swap(s[i], s[nxt]); } for (auto j : s[nxt]) { s[i].insert(j); } } if (adj[i].size() == 1) s[i].insert(0); ll val = *s[i].begin(); s[i].erase(s[i].begin()); s[i].insert(val - parc); } int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, k; 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++) { s[j].clear(); } dfs(i, 0, 0); ll sum = 0; int cnt = 0; for (auto j : s[i]) { if (cnt == k) break; sum += j; cnt++; } cout << -sum << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...