#include <bits/stdc++.h>
using namespace std;
int maxi = 0;
map<pair<int, int>, int> mp;
void printpath(vector<int>& path) {
  int size = path.size();
  int prev = path[0], pres, cost = 0;
  for (int i = 1; i < size; i++) {
    pres = path[i];
    cost += mp[{prev, pres}];
    prev = pres;
  }
  if (cost > maxi) maxi = cost;
}
int isNotVisited(int x, vector<int>& path) {
  int size = path.size();
  for (int i = 0; i < size; i++)
    if (path[i] == x) return 0;
  return 1;
}
void findpaths(vector<vector<int>>& g, int src, int dst, int v) {
  queue<vector<int>> q;
  vector<int> path;
  path.push_back(src);
  q.push(path);
  while (!q.empty()) {
    path = q.front();
    q.pop();
    int last = path[path.size() - 1];
    if (last == dst) printpath(path);
    for (int i = 0; i < g[last].size(); i++) {
      if (isNotVisited(g[last][i], path)) {
        vector<int> newpath(path);
        newpath.push_back(g[last][i]);
        q.push(newpath);
      }
    }
  }
}
int main() {
  vector<vector<int>> g;
  int n, src, dest, wt;
  cin >> n;
  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> src >> dest >> wt;
    g[src].push_back(dest);
    g[dest].push_back(src);
    mp[{src, dest}] = wt;
    mp[{dest, src}] = wt;
  }
  vector<int> desti;
  for (int i = 0; i < n; i++)
    if (g[i].size() == 1) desti.push_back(i);
  for (int i = 0; i < desti.size(); i++) findpaths(g, 0, desti[i], n);
  cout << maxi << '\n';
  return 0;
}
