#include <bits/stdc++.h>
using namespace std;
int dist[105];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
vector<pair<int, int> > al[105];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int u, v, c;
    scanf("%d %d %d", &u, &v, &c);
    al[u].push_back(make_pair(v, c));
    al[v].push_back(make_pair(u, c));
  }
  memset(dist, -1, sizeof(dist));
  pq.push(make_pair(0, 0));
  dist[0] = 0;
  while (!pq.empty()) {
    pair<int, int> c = pq.top();
    pq.pop();
    int d = c.first;
    int x = c.second;
    if (d != dist[x]) continue;
    for (auto i : al[x]) {
      if (dist[i.first] == -1 || dist[i.first] > d + i.second) {
        dist[i.first] = d + i.second;
        pq.push(make_pair(dist[i.first], i.first));
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < n; i++) {
    ans = max(ans, dist[i]);
  }
  printf("%d", ans);
}
