#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
struct Vertex_ {
  vector<pair<Vertex_*, int>> adj;
  int dist;
  Vertex_() : dist(inf) {}
};
typedef Vertex_* Vertex;
void dfs(Vertex v) {
  for (auto p : v->adj) {
    Vertex to = p.first;
    if (to->dist == inf) {
      to->dist = v->dist + p.second;
      dfs(to);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  vector<Vertex> g(n);
  for (int i = 0; i < n; ++i) g[i] = new Vertex_();
  for (int i = 1; i < n; ++i) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    g[a]->adj.push_back({g[b], c});
    g[b]->adj.push_back({g[a], c});
  }
  g[0]->dist = 0;
  dfs(g[0]);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, g[i]->dist);
  }
  printf("%d", ans);
  return 0;
}
