#K50492. Minimum Resilience Cost of a Power Grid

    ID: 28876 Type: Default 1000ms 256MiB

Minimum Resilience Cost of a Power Grid

Minimum Resilience Cost of a Power Grid

The power grid is modeled as a tree with N nodes (substations) and N-1 edges connecting them. Each edge connects two substations and has an associated cost that represents the expense to reinforce the connection. Since the structure forms a tree, every edge is part of the unique path between some nodes. The task is to compute the minimum resilience cost required to secure the grid, which is simply the sum of the weights of all the edges.

Note: The input is provided via stdin and the output must be printed to stdout. If there are any formulas, they are given in LaTeX format. For example, the sum can be represented as:

\(\text{Total Cost} = \sum_{i=1}^{N-1} w_i\)

inputFormat

The input is read from stdin and has the following format:

  • The first line contains a single integer N representing the number of nodes in the power grid.
  • The next N-1 lines each contain three integers u, v, and w indicating that there is an edge between nodes u and v with a weight w.

You may assume that the given graph is a tree (i.e., it is connected and contains no cycles).

outputFormat

Output a single integer to stdout which is the sum of the weights of all the edges, representing the minimum resilience cost of the power grid.

## sample
4
1 2 3
2 3 4
3 4 5
12