Submit solution

Points:
7 (partial)

Time limit:
1.0s

Memory limit:
256M

Author:

Problem type

Allowed languages

Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, ~~CommonLisp~~, D, Dart, F#, Forth, Fortran, Go, ~~Groovy~~, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, ~~Nim~~, ~~ObjC~~, OCaml, ~~Octave~~, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Roger, Jessica, and Victor held an impromptu math contest, where Roger promptly got third place (what did you expect?). The third place prize was the second-longest path in a weighted tree with nodes. However, when he went to collect his prize, he felt as though he had been scammed. Thus, he hires you to write a program to print the length of this path so that he may file a formal complaint to the contest organizers.

#### Constraints

For all subtasks, and .

##### Subtask 1 [20%]

##### Subtask 2 [80%]

#### Input Specification

The first line of input will contain .

The next lines of input will contain 3 space-separated integers, , indicating there exists an edge of weight between nodes and .

#### Output Specification

A single integer, the length of the second-longest path in the tree.

#### Sample Input 1

```
4
1 2 1
1 3 1
1 4 1
```

#### Sample Output 1

`2`

#### Sample Input 2

```
5
1 2 1
2 3 1
3 4 1
4 5 1
```

#### Sample Output 2

`3`

## Comments