There are $$$n$$$ vertices connected by $$$n-1$$$ roads. Ignoring direction, the roads form a tree.
For every road, traveling in its two directions may have different costs. An input line $$$u\ v\ a\ b$$$ means that traveling from $$$u$$$ to $$$v$$$ costs $$$a$$$, while traveling from $$$v$$$ to $$$u$$$ costs $$$b$$$.
For every possible starting vertex $$$r$$$, find the sum of the costs of the unique directed trips from $$$r$$$ to all vertices. The trip from $$$r$$$ to itself has cost zero.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$).
Each of the next $$$n-1$$$ lines contains four integers $$$u$$$, $$$v$$$, $$$a$$$, and $$$b$$$ ($$$1 \le u,v \le n$$$, $$$u \ne v$$$, $$$1 \le a,b \le 10^6$$$). The undirected edges $$$(u,v)$$$ form a tree. The costs of directions $$$u\to v$$$ and $$$v\to u$$$ are $$$a$$$ and $$$b$$$, respectively.
Print $$$n$$$ integers. The $$$r$$$-th integer must be the sum of travel costs from vertex $$$r$$$ to every vertex.
1
0
31 2 4 72 3 2 5
10 9 17
42 1 3 82 3 4 64 2 5 2
30 9 23 22
All required sums fit in signed 64-bit integers.
| Название |
|---|


