#C4929. Find the Shortest Cycle in a Circular Park

    ID: 48521 Type: Default 1000ms 256MiB

Find the Shortest Cycle in a Circular Park

Find the Shortest Cycle in a Circular Park

You are given a circular park with n landmarks connected by n walkways forming a cycle. Each walkway connects two landmarks and has an associated length. Your task is to compute the length of the cycle which is simply the sum of the lengths of all the walkways.

More formally, if the walkways have lengths \(c_1, c_2, \dots, c_n\), the total length is:

[ L = \sum_{i=1}^{n} c_i ]

You are required to read the input from standard input (stdin) and write the result to standard output (stdout).

inputFormat

The first line contains an integer n (3 ≤ n ≤ 105), representing the number of landmarks. Each of the following n lines contains three space-separated integers a, b, and c:

  • a and b are the landmarks connected by a walkway.
  • c is the length of the walkway (1 ≤ c ≤ 109).

It is guaranteed that these walkways form a single cycle including all landmarks.

outputFormat

Output a single integer representing the total length of the cycle.

## sample
5
1 2 3
2 3 4
3 4 2
4 5 1
5 1 6
16