function Main(input) {
    var lines = input.split("\n");
    var n = parseInt(lines[0], 10);
    var nodes = new Array();
    for (var i = 0; i < n; i++) {
        nodes.push(new Node(i));
    }
    for (var i = 0; i < n - 1; i++) {
        var line = lines[i + 1].split(" ");
        var s = parseInt(line[0], 10);
        var t = parseInt(line[1], 10);
        var w = parseInt(line[2], 10);
        nodes[s].addNeighbor(nodes[t], w);
        nodes[t].addNeighbor(nodes[s], w);
    }
    nodes[0].dfs();
    var maxDist = 0;
    for (var i = 0; i < n; i++) {
        maxDist = Math.max(maxDist, nodes[i].sndSearch());
    }
    console.log(maxDist);
}

function Node(number) {
    this.number = number;
    this.neighbors = new Array();
    this.searched = false;
    this.maxDistSet = new NodeDistanceSet(this, 0);
    this.sndDistSet = new NodeDistanceSet(this, 0);
    this.notSearchedNode = new NodeDistanceSet(this, 0);
    this.addNeighbor = function(node, distance) {
        this.neighbors.push(new NodeDistanceSet(node, distance));
    }
    this.dfs = function() {
        var neighborNum = this.neighbors.length;
        this.searched = true;
        for (var i = 0; i < neighborNum; i++) {
            var n = this.neighbors[i];
            if (!n.node.searched) {
                var dist = n.node.dfs() + n.distance;
                this.changeDistSet(n.node, dist);
            } else {
                this.notSearchedNode = n;
            }
        }
        return this.maxDistSet.distance;
    }
    this.sndSearch = function() {
        var node = this.notSearchedNode.node;
        if (node == this) {
            return this.maxDistSet.distance + this.sndDistSet.distance;
        }
        var distance = this.notSearchedNode.distance;
        if (node.maxDistSet.node != this) {
            this.changeDistSet(node, node.maxDistSet.distance + distance);
        } else {
            this.changeDistSet(node, node.sndDistSet.distance + distance);
        }
        return this.maxDistSet.distance + this.sndDistSet.distance;
    }
    this.changeDistSet = function(node, distance) {
        if (distance > this.maxDistSet.distance) {
            this.sndDistSet = this.maxDistSet;
            this.maxDistSet = new NodeDistanceSet(node, distance);
        } else if (distance > this.sndDistSet.distance) {
            this.sndDistSet = new NodeDistanceSet(node, distance);
        }
    }
}

function NodeDistanceSet(node, distance) {
    this.node = node;
    this.distance = distance;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));