#include <algorithm>
#include <array>
#include <cstddef>
#include <iostream>
#include <vector>

const int nmax = 100005;
struct edge {
  int node;
  int weight;

  edge(int n, int w) : node(n), weight(w){};
};

int ans = 0;
std::array<std::vector<edge>, nmax> adjlist;

int dfs(int current, int parent) {
  std::vector<int> dist;
  for (size_t i = 0; i < adjlist[current].size(); ++i) {
    auto e = adjlist[current][i];
    if (e.node != parent) {
      dist.push_back(e.weight + dfs(e.node, current));
    }
  }

  // std::cout << current << ": ";
  // for (size_t i = 0; i < dist.size(); ++i) {
  //   std::cout << dist[i] << " ";
  // }
  // std::cout << std::endl;

  if (dist.size() >= 1) {
    std::sort(dist.begin(), dist.end(), [](int a, int b) { return a > b; });
    dist.push_back(0);
    ans = std::max(ans, dist[0] + dist[1]);
    return dist[0];
  } else {
    return 0;
  }
}

int main() {
  int n;
  std::cin >> n;

  int s, t, w;
  for (int i = 0; i < n - 1; ++i) {
    std::cin >> s >> t >> w;
    adjlist[s].push_back(edge(t, w));
    adjlist[t].push_back(edge(s, w));
  }

  dfs(0, -1);
  std::cout << ans << std::endl;
}

