#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long int ncr(long long int x, long long int y) {
  if (x == y) {
    return 1;
  }
  if (x == 0) {
    return 0;
  }
  long long int ans = 1;
  if (y > x) {
    return 0;
  }
  for (long long int i = 0; i < y; i++) {
    ans = ans * (x);
    ans = ans / (i + 1);
    x--;
    ans = ans % (long long int)(1LL << 32);
  }
  return ans;
}
long long int power(long long int x, long long int y) {
  long long int ans = 1;
  while (y) {
    if (y & 1) {
      ans = ans * x;
      ans = ans % (long long int)(1LL << 32);
    }
    x = x * x;
    x = x % (long long int)(1LL << 32);
    y = y >> 1;
  }
  return ans;
}
struct Dual {
  long long int edge;
  long long int weight;
  Dual() { weight = -1; }
};
int dfs(vector<Dual> v[], long long int curr, long long int sum, bool flag[]) {
  flag[curr] = false;
  long long int tot = 0;
  for (int i = 0; i < v[curr].size(); i++) {
    Dual d = v[curr][i];
    if (flag[d.edge]) {
      long long int x = dfs(v, d.edge, sum + d.weight, flag);
      tot = max(tot, x);
    } else {
      tot = max(tot, sum);
      continue;
    }
  }
  sum = tot;
  return sum;
}
void solve() {
  long long int n;
  cin >> n;
  vector<Dual> v[n];
  for (int i = 0; i < n; i++) {
    long long int a, b, c;
    cin >> a >> b >> c;
    Dual d;
    d.edge = b;
    d.weight = c;
    Dual z;
    z.edge = a;
    z.weight = c;
    v[a].push_back(d);
    v[b].push_back(z);
  }
  bool flag[n];
  memset(flag, true, sizeof(flag));
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    if (flag[i]) {
      long long int p = dfs(v, i, 0, flag);
      ans = max(ans, p);
    }
  }
  cout << ans << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
