Flowery Trails

No attempts yetTime limit2sMemory limit256 MB

Problem

A national park has PP points of interest and TT two-way trails that link them. The entrance is point 00 and the highest peak is point P1P-1.

Visitors walk from the entrance to the highest peak along a shortest path. Different visitors choose different shortest paths, so every shortest path is used by someone. A trail is popular when it lies on at least one shortest path from the entrance to the highest peak.

The park manager plants flowers along both sides of every popular trail, so a popular trail of length ll metres needs 2l2l metres of flowers. Compute the total length of flowers needed.

Two points can be linked by more than one trail, and a trail can start and end at the same point. Each trail counts separately, and a popular trail counts once no matter how many shortest paths use it. At least one path from the entrance to the highest peak exists.

Input

The first line has two integers PP and TT.

Each of the next TT lines has three integers p1p_1, p2p_2, and ll, meaning that a two-way trail of length ll metres links point p1p_1 and point p2p_2. The two points are not necessarily distinct.

Integers on the same line are separated by a single space.

Output

Print one integer, the total length of flowers in metres.

Limits

  • 2P100002 \le P \le 10000, the number of points.
  • 1T2500001 \le T \le 250000, the number of trails.
  • 1l10001 \le l \le 1000, the length of a trail.
  • 0p1,p2P10 \le p_1, p_2 \le P-1.