Subway Map

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

In the year 2120 there is a vast subway network under all of Lund, consisting of NN stations and MM tunnels. Each tunnel connects two stations and the stations are numbered 11, \ldots, NN.

Erik has had enough of Skånetrafiken's terrible route planning software and plans to build his own. To do this, he needs to know the length of each of the tunnels, but the subway map is incomplete in this regard. By looking out the window, Erik has noticed that some tunnels have special cables running alongside them, probably for providing power to the stations. The cables connect the stations so that every station is connected to the central station (the station numbered 11). Knowing how greedy Skånetrafiken is, he is certain that the cables are placed so that the total length of cable is minimized.

Erik knows the precise length of some tunnels, and which tunnels contain cables. Using this information he wants to find the minimum possible length for each tunnel with unknown length. Unfortunately, Erik's algorithm isn't efficient enough to process the enormous size of Lund's subway network. Can you help him by implementing a more efficient algorithm?

입력

The first line of input contains two integers NN and MM, where 2N1052 \leq N \leq 10^5 and  N1M2105N - 1 \leq M \leq 2 \cdot 10^5, the number of stations and the number of tunnels, respectively. Each of the next MM lines contains the values a_ia\_i, b_ib\_i, l_il\_i and c_ic\_i. The integers a_ia\_i and b_ib\_i, with 1a_i,b_iN1 \leq a\_i, b\_i \leq N and a_ib_ia\_i\neq b\_i, denote the two stations connected by the iith tunnel. The value l_il\_i is either an integer satisfying 1l_i1091 \leq l\_i \leq 10^9, the length of the iith tunnel if it is known, or a question mark “?”. Finally, c_ic\_i is 11 if the iith tunnel contains a cable, and 00 if not.

It is guaranteed that there is at most one tunnel connecting the same pair of stations, and that it is possible to travel between any pair of stations using the subway. It is also guaranteed that there exists a path between any station and station number 11 using only tunnels where c_i=1c\_i = 1.

출력

For each tunnel with l_i=?l\_i=`?`, output one line with a single integer, the minimum possible length for that tunnel. Tunnel lengths should be output in the same order as the tunnels are listed in the input.

힌트

In the first sample case, the minimal distance for the unknown tunnel (between stations 33 and 11) is 55. This is because, if the length were less than 55, it would be more efficient for Skånetrafiken to run cables through the second and third tunnels.