Road Construction

Given a weighted bidirectional graph, find the minimum total building cost of a spanning subgraph that keeps every pairwise connection and preserves the shortest distance from the capital to every city.

Medium7GraphShortest pathMinimum spanning treeGreedyInterviewNo attempts yetTime limit8sMemory limit512 MB

Problem

King Mercer rules the ACM kingdom. The kingdom has one capital and several other cities, and right now it has no roads at all. He drew up a plan to build roads between the capital and the cities, but the plan turned out to cost far more than he expected.

To cut the cost, he decided to make a new plan by removing some roads from the original one. The new plan has to satisfy both of these conditions:

  • For every pair of cities there is a route of roads connecting them.
  • The shortest distance from the capital to each city is the same as in the original plan.

Several plans may satisfy the conditions, and King Mercer wants the cheapest one. Write a program that reads the original plan and computes the cost of a cheapest plan that satisfies the conditions.

Input

The input has several datasets. Each dataset has the following form.

N M
u1 v1 d1 c1
.
.
.
uM vM dM cM

The first line of a dataset has two integers, the number of cities NN and the number of roads in the original plan MM (1N100001 \le N \le 10000, 0M200000 \le M \le 20000).

Each of the next MM lines describes one road of the original plan with four integers uiu_i, viv_i, did_i, cic_i (1ui,viN1 \le u_i, v_i \le N, uiviu_i \ne v_i, 1di10001 \le d_i \le 1000, 1ci10001 \le c_i \le 1000). They mean that a road connects city uiu_i and city viv_i, its length is did_i, and building it costs cic_i.

Every road is bidirectional. No two roads connect the same pair of cities. City 1 is the capital of the kingdom. In the original plan every city is reachable from the capital.

The input ends with a line holding two zeros separated by a space. Do not process that line as a dataset.

Output

For each dataset, print the minimum cost of a plan that satisfies the conditions on one line.