import std.stdio;
import std.array;
import std.string;
import std.container;
import std.ascii;
import std.random;
import std.algorithm;
import std.conv;
import std.range;
import std.math;
import std.format;
import std.typecons;
import std.numeric;
import std.datetime;

/*
  ??????????????????, ?????§??¨?????¨, ??¨?????????, ????????????????????????????????????
*/

/**
  src???????????°??????G, dst???King's Graph??§??????Gemb
*/
int n, m, u, v, c;
edge[][] g;

void main() {
  n = readln.chomp.to!int;
  g = new edge[][](n, 0);
  for (int i = 0; i < n-1; ++i) {
    auto l = readln.chomp.split.map!(to!int).array;
    g[l[0]] ~= edge(l[0], l[1], l[2]);
    g[l[1]] ~= edge(l[1], l[0], l[2]);
  }

  edge e = treeDiameter(g);
  writeln(e.cost);
}

/***************************************************************************/
// c++???pair??£??????
struct pair {
  int first, second;
}

struct edge {
  int u, v, cost;
}

class queue(T) {
  T[] p;

  this() {}
  this(T p) {
    this.p ~= p;
  }
  ~this() {}

  void push(T x) {
    p ~= x;
  }

  void pop() {
    assert(p.length > 0);
    p.popFront();
  }

  T front() {
    assert(p.length > 0);
    return p[0];
  }

  bool empty() {
    if (p.length == 0) return true;
    else return false;
  }
}

// pair(??´???, ??´??????????????????)
edge treeDiameter(edge[][] graph) {
  int s;
  pair d1, d2; // pair(distance, vertex)
  bool[] used = new bool[](n);

  d1 = dfs(graph, used, pair(0, s));
  used[] = false;
  d2 = dfs(graph, used, pair(0, d1.second));

  if (d1.second > d2.second) swap(d1.second, d2.second);

  return edge(d1.second, d2.second, d2.first);
}

// ?????????????????????????????????????????????????????????????????????????????¨???????????§????????¢?????????
pair dfs(edge[][] graph, bool[] used, pair p) {
  used[p.second] = true;

  pair ret = p;

  foreach(nv; graph[p.second]) {
    if (!used[nv.v]) {
      pair tmp = dfs(graph, used, pair(p.first + nv.cost, nv.v));
      if (ret.first < tmp.first) {
        ret = tmp;
      }
    }
  }

  return ret;
}


/***************************************************************************/