#P3304. [SDOI2013] 直径
[SDOI2013] 直径
Description
Xiao Q recently learned some graph theory. According to the textbook, we have the following definitions. A tree is an undirected graph that is connected and acyclic, where each edge has a positive integer weight representing its length. If a tree has nodes, it can be shown that it has exactly edges.
Path: In a tree, between any two nodes there exists at most one simple path. We use to denote the sum of the lengths of the edges on the path between and . We call the distance between nodes and .
Diameter: In a tree, the longest path is called the diameter of the tree. The tree’s diameter may not be unique.
Now Xiao Q wants to know, for a given tree, what the length of its diameter is, and how many edges are traversed by all diameters.
Input Format
The first line contains an integer , the number of nodes.
The next lines each contain three integers , indicating there is an undirected edge of length between nodes and .
Output Format
Output two lines. The first line contains one integer, the length of the diameter. The second line contains one integer, the number of edges that are traversed by all diameters.
6
3 1 1000
1 4 10
4 2 100
4 5 50
4 6 100
1110
2
Hint
[Sample Explanation]
There are two diameters: the path from to and the path from to . Both diameters pass through edge and edge .
For of the testdata: , , . The input graph forms a tree.
Translated by ChatGPT 5
京公网安备 11011102002149号