using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            var N = Sarray()[0];

            grf = new int[N].Select(_ => new List<pair<long, long>>()).ToArray();
            for (var i = 0; i < N - 1; ++i) 
            {
                var stw = Sarray();
                grf[stw[0]].Add(new pair<long, long>(stw[1], stw[2]));
                grf[stw[1]].Add(new pair<long, long>(stw[0], stw[2]));
            }
            dist = new long[N];
            pinfo = new long[N];
            maxdist = new long[N];
            lens = new long[2];
            dfs(0, -1);
            maxdfs(0, 0);
            WriteLine(maxdist.Max());
        }
        static List<pair<long, long>>[] grf;
        static long[] dist;
        static long[] maxdist;
        static long[] pinfo;
        static void dfs(long n, long p)
        {
            for(var i=0;i<grf[n].Count;++i)
            {
                var next = grf[n][i].v1;
                var nw = grf[n][i].v2;
                if (next == p) continue;
                dfs(next, n);
                dist[n] = Max(dist[n], dist[next] + nw);
            }
        }
        static long[] lens;
        static void maxdfs(long n, long p)
        {
            lens[0] = pinfo[n];
            lens[1] = 0;
            for (var i = 0; i < grf[n].Count; ++i)
            {
                var next = grf[n][i].v1;
                var nw = grf[n][i].v2;
                if (next == p) continue;
                var w = dist[next] + nw;
                if (lens[1] <= w)
                    lens[1] = w;
                if (lens[0] <= lens[1])
                {
                    var t = lens[1];
                    lens[1] = lens[0];
                    lens[0] = t;
                }
            }
            maxdist[n] = lens[0] + lens[1];
            for (var i = 0; i < grf[n].Count; ++i)
            {
                var next = grf[n][i].v1;
                var nw = grf[n][i].v2;
                if (next == p) continue;
                pinfo[next] = lens[0];
                if (dist[next] +nw == lens[0])
                    pinfo[next] = lens[1];
                pinfo[next] += nw;
            }
            for (var i = 0; i < grf[n].Count; ++i)
            {
                var next = grf[n][i].v1;
                if (next == p) continue;
                maxdfs(next, n);
            }

        }
        public class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U>
        {
            public T v1;
            public U v2;
            public pair(T v1, U v2)
            {
                this.v1 = v1;
                this.v2 = v2;
            }
            public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2);
        }
    }
}


Measured memory_bytes: 53252