#include<vector>
#include<tuple>
//
class Tree {
public:
  explicit Tree(int n);
  void join(int u, int v, int w);
  int diameter() const;
private:
  struct Edge {int from, to; int weight;};
  struct Farthest {int vertex; int cost;};
  const Farthest diameter_dfs(int current, int previous) const;
  std::vector<std::vector<Edge>> edge_;
};
// ?????????????????????
Tree::Tree(int n) : edge_(n) {}
// ????????????
void Tree::join(int u, int v, int w) {
  edge_[u].push_back({u, v, w});
  edge_[v].push_back({v, u, w});
}
// ??´???
int Tree::diameter() const {
  int v = diameter_dfs(0, 0).vertex;
  return diameter_dfs(v, v).cost;
}
const Tree::Farthest Tree::diameter_dfs(int current, int previous) const {
  Farthest result({current, 0});
  for(const auto& e: edge_[current]) {
    if(e.to == previous) continue;
    auto f = diameter_dfs(e.to, e.from);
    f.cost += e.weight;
    if(result.cost < f.cost) result = f;
  }
  return result;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  Tree tree(n);
  for(int i = 0; i < n - 1; ++i) {
    int s, t, w;
    cin >> s >> t >> w;
    tree.join(s, t, w);
  }
  cout << tree.diameter() << endl;
}