#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
11144 KB |
Output is correct |
2 |
Correct |
94 ms |
12448 KB |
Output is correct |
3 |
Correct |
69 ms |
10760 KB |
Output is correct |
4 |
Correct |
73 ms |
11096 KB |
Output is correct |
5 |
Correct |
71 ms |
12212 KB |
Output is correct |
6 |
Correct |
72 ms |
11052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |