View as PDF

Points: 10
Time limit: 1.0s
Java 8 1.4s
Memory limit: 128M

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

Given a weighted tree with vertices and edges, your task is to find the diameter and radius of the tree.

We say the diameter of the tree is the largest distance between any two points.

We say the radius of a tree is the minimum of the maximum distances for all points.

#### Input Specification

First line, one integer , denoting the number of vertices.

The next lines will have three integers , denoting that there is a connection between vertices and , with a weight of .

#### Output Specification

On separate lines, output the diameter, and the radius of the tree in that order.

#### Sample Input

5
1 2 1
2 3 2
3 4 5
2 5 7

#### Sample Output

14
7

#### Sample Explanation

The graph is depicted below:

We can see that the distance between node and is the greatest distance, thus is diameter.

We can see that the minimum value between the maximum distances along the diameter are , thus is the radius.