#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

struct node {
  int id;
  int weight;
  struct node *next;
};

struct node **list;
int *dis;

void Insert(int, int, int);
void Bfs(int, int);
int main(void)
{
  int i, n, s, t, w, point = 0, maxdis = 0;
  scanf("%d", &n);
  list = (struct node**)malloc(sizeof(struct node*) * n);
  dis = (int*)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) list[i] = NULL;
  for (i = 0; i < n- 1; i++) {
    scanf("%d %d %d", &s, &t, &w);
    Insert(s, t, w);
  }
  Bfs(0, n);
  for (i = 1; i < n; i++) {
    if (dis[i] == INT_MAX) continue;
    if (maxdis < dis[i]) {
      maxdis = dis[i];
      point = i;
    }
  }
  Bfs(point, n);
  for (i = 0; i < n; i++) {
    free(list[i]);
    if (dis[i] == INT_MAX) continue;
    if (maxdis < dis[i]) maxdis = dis[i];
  }
  printf("%d\n", maxdis);
  free(list);
  free(dis);
}
void Insert(int a, int b, int w)
{
  struct node *p = (struct node*)malloc(sizeof(struct node));
  p->id = b;
  p->weight = w;
  p->next = list[a];
  list[a] = p;
  p = (struct node*)malloc(sizeof(struct node));
  p->id = a;
  p->weight = w;
  p->next = list[b];
  list[b] = p;
}
void Bfs(int point, int size)
{
  int i, ptr_front = 0, ptr_back = 0, *queue = (int*)malloc(sizeof(int) * size);
  struct node *n;
  for (i = 0; i < size; i++) dis[i] = INT_MAX;
  queue[ptr_back++] = point;
  dis[point] = 0;
  while (ptr_front != ptr_back) {
    int u = queue[ptr_front++];
    for (n = list[u]; n != NULL; n = n->next) {
      int edge = n->weight;
      if (dis[n->id] == INT_MAX) {
        dis[n->id] = dis[u] + edge;
        queue[ptr_back++] = n->id;
      }
    }
  }
  free(queue);
}
