# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
786381 |
2023-07-18T07:18:17 Z |
이동현(#10029) |
Paths (RMI21_paths) |
C++17 |
|
104 ms |
19780 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<vector<vector<int>>> way(n);
for(int i = 1; i < n; ++i){
int x, y, z;
cin >> x >> y >> z;
--x, --y;
way[x].push_back({y, z});
way[y].push_back({x, z});
}
auto getdis = [&](auto&&self, int x, int pr, int ndis, vector<int>&vc)->void{
vc[x] = ndis;
for(auto&nxt:way[x]){
if(nxt[0] == pr){
continue;
}
self(self, nxt[0], x, ndis + nxt[1], vc);
}
};
vector<int> imsi(n);
getdis(getdis, 0, -1, 0, imsi);
pair<int, int> mx1 = {-1, -1};
for(int i = 0; i < n; ++i){
mx1 = max(mx1, {imsi[i], i});
}
vector<int> dis1(n), dis2(n);
getdis(getdis, mx1.second, -1, 0, dis1);
pair<int, int> mx2 = {-1, -1};
for(int i = 0; i < n; ++i){
mx2 = max(mx2, {dis1[i], i});
}
getdis(getdis, mx2.second, -1, 0, dis2);
for(int i = 0; i < n; ++i){
cout << max(dis1[i], dis2[i]) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
18944 KB |
Output is correct |
2 |
Correct |
104 ms |
19780 KB |
Output is correct |
3 |
Correct |
66 ms |
18892 KB |
Output is correct |
4 |
Correct |
98 ms |
18676 KB |
Output is correct |
5 |
Correct |
90 ms |
19432 KB |
Output is correct |
6 |
Correct |
88 ms |
18464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |