Submission #578564

#TimeUsernameProblemLanguageResultExecution timeMemory
578564maomao90Paths (RMI21_paths)C++17
36 / 100
1095 ms9460 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int n, k; vector<pair<int, int>> adj[MAXN]; multiset<long long> st; long long mx[MAXN]; void dfs(int u, int p) { mx[u] = 0; bool leaf = 1; for (auto [v, w] : adj[u]) { if (v == p) continue; leaf = 0; dfs(v, u); st.erase(st.find(mx[v])); st.insert(mx[v] + w); mx[u] = max(mx[u], mx[v] + w); } if (leaf) { st.insert(0); } } int main() { cin >> n >> k; for (int i = 1; i < n; i++) { int a, b, c; cin >> a >> b >> c; adj[a].push_back({b, c}); adj[b].push_back({a, c}); } for (int i = 1; i <= n; i++) { st.clear(); dfs(i, -1); long long ans = 0; while (st.size() > k) { st.erase(st.begin()); } for (long long x : st) { ans += x; } cout << ans << '\n'; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:38:26: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |         while (st.size() > k) {
      |                ~~~~~~~~~~^~~
#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...