Taxi
시간 제한7초메모리 제한2048 MB
가중치가 있는 트리에서 각 도시마다 요금이 a_v + b_v * 거리인 택시를 갈아타며 도시 1에서 다른 모든 도시로 가는 최소 비용을 구한다.
문제
There are cities that are connected by roads, forming a tree. Note that each road has a given length.
When you are at city , you can take a taxi of the local taxi company to any other city . For this, you have to pay cookies, where is the distance from to . In other words, you have to pay the base cost and additionally for each unit of distance traveled.
You are currently at city , and for each other city , you want to know the minimum cost to get there.
입력
The first line contains one integer () --- the number of cities.
The second line contains integers () --- the base costs of the taxis.
The third line contains integers () --- the cost per distance.
Then lines follow, describing the roads between the cities. Every line contains three integers and (, , ) describing a bidirectional road between cities and of length .
출력
Output a single line containing integers. The -th of them should be the minimum cost to get to city .
힌트
Consider the cost to get to city in the first sample: Driving directly from to would cost . It is better to drive from to with a cost of and take a second taxi from to with a cost of . While the distance traveled is larger, the cost is still smaller.