Submission #717236

#TimeUsernameProblemLanguageResultExecution timeMemory
717236vjudge1Paths (RMI21_paths)C++17
12 / 100
94 ms12448 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<vector<pair<int, int>>> g; void dfs(int v, int p, vector<ll>& d) { for (auto [x, w] : g[v]) { if (x == p) continue; d[x] = d[v] + w; dfs(x, v, d); } } int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; g.resize(n + 1); for (int i = 0; i < n - 1; i++) { int u, v, c; cin >> u >> v >> c; g[u].push_back({v, c}); g[v].push_back({u, c}); } vector<ll> da(n + 1), db(n + 1); dfs(1, 0, da); int a = max_element(da.begin(), da.end()) - da.begin(); da.assign(n + 1, 0); dfs(a, 0, da); int b = max_element(da.begin(), da.end()) - da.begin(); dfs(b, 0, db); for (int i = 1; i <= n; i++) { cout << max(da[i], db[i]) << "\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...