

1967번과 다를 게 없는 문제였다. 그냥 입력받는 부분만 조금 바꾸고 최댓값만 수정해서 제출했다.
1967번 해설: (https://karma2.tistory.com/6)
#include <bits/stdc++.h>
#define MAX 100001
using namespace std;
struct Pair {
int fir, sec;
};
vector<Pair> v[MAX];
bool visited[MAX] = {false};
int Max = 0, End = 0; //최댓값, 끝지점 변수
void dfs(int a, int l) {
if (visited[a]) return;
visited[a] = true;
if (Max < l) //보다 더 큰 최댓값을 발견했다면
Max = l, End = a;
for (int i = 0; i < (int)v[a].size(); i++)
dfs(v[a][i].fir, l + v[a][i].sec);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n; cin >> n;
for (int i = 0; i < n; i++) {
int a, b, c; cin >> a;
while (1) {
cin >> b;
if (b == -1) break;
cin >> c;
v[a].push_back({b, c});
v[b].push_back({a, c});
}
}
dfs(1, 0); //1부터 시작해서 가장 멀리 있는 노드 구하기
Max = 0;
memset(visited, false, sizeof(visited)); //초기화
dfs(End, 0);
cout << Max;
}