Wooden pipeline

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

문제

In a land far, far away there lived a wise king who ruled NN cities. The king decided to improve life in his kingdom and made the gentry get busy with innovations, modernization, and nanotechnologies. The gentry came up with an innovative pipeline network. Since they haven't really mastered the nanotubes yet, the pipelines are made of wood.

The wooden pipelines connect all cities into a single network, where any city can be reached from any other city. The network consists of N1N-1 pipelines. Each pipeline leads directly from one city to another without any forkings. The additional pipelines were planned according to the original costs estimate, but in the end they ran out of wood.

We know the capacity of each pipeline in each direction, i.e. the amount of fluid which can pass through it in a unit of time. The capacity of a pipeline in the opposite directions can be different, due to the (in)famous craftsmanship of the kingdom.

The king is deeply saddened, contemplating the fruit of his denizens' labor. He cannot think of a liquid to pump through the pipelines. Milk would go sour, and the kingdom is not that rich in mead. On the other hand, they could pump water, in case there is drought somewhere. The king wants to know the efficiency of the pipeline system in case of a drought.

Assume there is a drought in the city uu. This splits all other cities into two types: terminal and transitional cities. A city is transitional if it has a pipeline leading to a city which is more distant from the city uu, with the distance calculated along the pipelines. All other cities are terminal. You can take water from all terminal cities in any volume and pump it along the pipelines to the city uu. You cannot take water from transitional cities.

Define the maximum volume of water per unit of time that can be pumped through the pipelines from the terminal cities to the city uu. Drought can affect any of the cities, so calculate the answer for each case of uu.

입력

The first line of the input file contains a single integer NN --- the number of cities (1N31051 \le N \le 3 \cdot 10^5). The remaining N1N-1 lines describe the pipelines, one per line. Each pipeline is described by four numbers: aa --- the number of the city where the pipeline starts, bb --- the number of the city where the pipeline ends, C_abC\_{ab} --- pipeline capacity in the direction from aa to bb, C_baC\_{ba} --- pipeline capacity in the direction from bb to aa (1abN1 \le a \neq b \le N, 1C_ab,C_ba1051 \le C\_{ab}, C\_{ba} \le 10^5).

It is guaranteed that you can reach any town from any other town along the pipeline system.

출력

In the input file, print NN integers, one per line. Each kkth number defines the maximal volume of water per unit of time that can be pumped into the city with the number kk in case it is stricken by drought.