#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define MAX 10002
vector<pair<int, int>> node[MAX];
bool vis[MAX];
int res, endPoint;
void DFS(int p = 1, int len = 0)
{
if (vis[p])
return;
vis[p] = true;
if (res < len)
{
res = len;
endPoint = p;
}
for (int i = 0; i < node[p].size(); i++)
DFS(node[p][i].first, len + node[p][i].second);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
for (int i = 0; i < n - 1; i++)
{
int a, b, c; cin >> a >> b >> c;
node[a].push_back({ b, c });
node[b].push_back({ a, c });
}
DFS();
res = 0;
fill(vis, vis + MAX, false);
DFS(endPoint);
cout << res;
return 0;
}
'코딩테스트 > 백준' 카테고리의 다른 글
[골4] 2580 - 스도쿠 (0) | 2023.07.31 |
---|---|
[골5] 13549 - 숨바꼭질 3 (0) | 2022.12.30 |
[실3] 2407 - 조합 (0) | 2022.12.27 |
[골4] 11404 - 플로이드 (0) | 2022.12.22 |
[골5] 15686 - 치킨 배달 (0) | 2022.12.22 |