// AOJ GRL_5_A Diameter of a Tree
// 2018.5.4 bal4u

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

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define INF   0x10101010
#define MAX_N 100002

typedef struct { int s, d; } QUE;
QUE que[MAX_N*2]; int top, end;
int n;
int hi[MAX_N], *to[MAX_N], *w[MAX_N];
int dist[MAX_N];

int bfs(int s)
{
	int i, t, d, nd;
	int ans_n, ans_d;

	memset(dist, INF, n<<2);
	que[0].s = s, que[0].d = 0, dist[s] = 0, top = 0, end = 1;
	ans_n = s, ans_d = 0;
	while (top != end) {
		s = que[top].s, d = que[top++].d;
		if (dist[s] < d) continue;
		if (d > ans_d) ans_d = d, ans_n = s;
		for (i = 0; i < hi[s]; i++) {
			t = to[s][i], nd = d+w[s][i];
			if (dist[t] > nd) {
				dist[t] = nd, que[end].s = t, que[end++].d = nd;
			}
		}
	}
	return ans_n;
}

int treeDiameter()
{
	int s, g;
	
	s = bfs(0);
	g = bfs(s);
	return dist[g];
}

int main()
{
	int s, t, x, i, j, k;
	int *memo;

	n = in();
	memo = malloc(n*12);
	j = 0; for (i = 1; i < n; i++) {
		memo[j++] = s = in();
		memo[j++] = t = in();
		memo[j++] = in();
		hi[s]++, hi[t]++;
	}
	for (i = 0; i < n; i++) if (hi[i]) {
		to[i] = malloc(hi[i]<<2), w[i] = malloc(hi[i]<<2);
	}
	memset(hi, 0, n<<2);
	j = 0; for (i = 1; i < n; i++) {
		s = memo[j++], t = memo[j++], x = memo[j++];
		k = hi[s]++, to[s][k] = t, w[s][k] = x;
		k = hi[t]++, to[t][k] = s, w[t][k] = x;
	}
	free(memo);

	printf("%d\n", treeDiameter());
	return 0;
}

