#include <bits/stdc++.h>
using namespace std;
int n, a, b, c, cost[105][105], loest[105], flag[105] = {1};
int main() {
  int i, j, k, t;
  scanf("%d", &n);
  for (i = 0; i <= n - 1; i++) {
    for (j = 0; j <= i; j++) {
      cost[i][j] = cost[j][i] = -1;
    }
  }
  for (i = 0; i < n - 1; i++) {
    scanf("%d %d %d", &a, &b, &c);
    cost[a][b] = cost[b][a] = c;
  }
  for (i = 1; i <= n - 1; i++) {
    loest[i] = cost[0][i];
  }
  for (i = 1; i <= n - 1; i++) {
    k = -1;
    for (j = 1; j <= n - 1; j++) {
      if (flag[j] == 0 && loest[j] > k) {
        t = j;
        k = loest[j];
      }
    }
    flag[t] = 1;
    for (j = 1; j <= n - 1; j++) {
      if (flag[j] == 0 && cost[t][j] != -1 && k + cost[t][j] > loest[j])
        loest[j] = k + cost[t][j];
    }
  }
  sort(loest, loest + n);
  printf("%d\n", loest[n - 1]);
  return 0;
}
