#K71907. Sum of Graph Edge Weights

    ID: 33635 Type: Default 1000ms 256MiB

Sum of Graph Edge Weights

Sum of Graph Edge Weights

You are given an undirected weighted graph with \(N\) nodes and \(M\) edges. Each edge is represented by two nodes and a weight. Your task is to calculate the sum of the weights of all the edges in the graph.

The input format is structured so that the first line of input provides two integers \(N\) and \(M\). Each of the following \(M\) lines contains three integers \(u\), \(v\), and \(w\) representing an edge between node \(u\) and node \(v\) with weight \(w\). If there are no edges (i.e. \(M = 0\)), the sum is 0.

Note: Self-loops and multiple edges may be present, and they should be considered in the sum.

inputFormat

The input is provided via stdin and has the following format:

  • The first line contains two integers \(N\) and \(M\) separated by a space.
  • The next \(M\) lines each contain three integers \(u\), \(v\) and \(w\) separated by spaces, representing an edge between nodes \(u\) and \(v\) with weight \(w\).

outputFormat

Print a single integer to stdout, which is the sum of the weights of all edges in the graph.

## sample
5 4
1 2 1
2 3 2
3 4 3
4 5 4
10