CF802J.Send the Fool Further! (easy)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on.

Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank?

Heidi's nn friends are labeled 00 through n1n-1 , and their network of connections forms a tree. In other words, every two of her friends aa , bb know each other, possibly indirectly (there is a sequence of friends starting from aa and ending on bb and such that each two consecutive friends in the sequence know each other directly), and there are exactly n1n-1 pairs of friends who know each other directly.

Jenny is given the number 00 .

输入格式

The first line of the input contains the number of friends nn ( 3<=n<=1003<=n<=100 ). The next n1n-1 lines each contain three space-separated integers uu , vv and cc ( 0<=u,v<=n10<=u,v<=n-1 , 1<=c<=1041<=c<=10^{4} ), meaning that uu and vv are friends (know each other directly) and the cost for travelling between uu and vv is cc .

It is guaranteed that the social network of the input forms a tree.

输出格式

Output a single integer – the maximum sum of costs.

输入输出样例

  • 输入#1

    4
    0 1 4
    0 2 2
    2 3 3
    

    输出#1

    5
    
  • 输入#2

    6
    1 2 3
    0 2 100
    1 4 2
    0 3 7
    3 5 10
    

    输出#2

    105
    
  • 输入#3

    11
    1 0 1664
    2 0 881
    3 2 4670
    4 2 1555
    5 1 1870
    6 2 1265
    7 2 288
    8 7 2266
    9 2 1536
    10 6 3378
    

    输出#3

    5551
    

说明/提示

In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 22 (incurring a cost of 100100 ), then friend 22 sends her to friend 11 (costing Heidi 33 ), and finally friend 11 relays her to friend 44 (incurring an additional cost of 22 ).

首页