HDU3534 给你一个树让你找出其中最长路径以及个数数
Description
In the Datastructure class of HEU, the teacher asks one problem: How to find the longestpath(路徑) of one treeand the number of such longest path?
Input
There are several test cases. The firstline of each case contains only one integer N, means there are N nodes in thetree. N-1 lines follow, each line has three integers w,v and len, indicate thatthere is one edge between node w and v., and the length of the edge is len.?
Output
For each testcase, output the length of longest path and its number in one line.
Sample Input
4
1 2 100
2 3 50
2 4 50
4
1 2 100
2 3 50
3 4 50
Sample Output
150 2
200 1
題意:給你一個樹讓你找出其中最長路徑以及個數(shù)。
思路:DFS可做
總結(jié)
以上是生活随笔為你收集整理的HDU3534 给你一个树让你找出其中最长路径以及个数数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 判断给定森林中有多少棵树特别版
- 下一篇: java中stack集合框架