Logo
(追記) (追記ここまで)

18425번 - Putovanje 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB103524754.651%

문제

Little Fabijan loves bars and travels. He wishes to drink beer coffee in each of the N towns in his country conveniently numbered from 1 to N. The towns are connected via (N − 1) bidirectional roads such that each town is reachable from any other town by traversing some of the roads. Fabijan decided to drink coffee in every town in order from town number 1 to town number N. Therefore, he starts from town number 1 (where he drinks his first coffee) and travels to town number 2 for his next cup of coffee. During that travel he might pass through a number of different towns but he won’t make a coffee stop in those towns. After drinking coffee in town 2, he will proceed to travel to town 3, and so on until he finally reaches town N where he will drink his last coffee.

In order to traverse a certain road, he needs to have a valid ticket. The i-th road can be traversed if you have either a single-pass ticket which costs Ci1 euros or a multi-pass ticket which costs Ci2 euros. For each road, Fabijan can decide to buy a single-pass ticket each time he needs to traverse that road or he might opt to buy a multi-pass ticket once.

Write a program that computes the smallest number of euros Fabijan needs to spend on tickets in order to successfully complete his travels.

입력

The first line contains an integer N (2 ≤ N ≤ 200 000) from task description.

In i-th of the next (N − 1) lines there are four integers Ai, Bi, Ci1, Ci2 (1 ≤ Ai, Bi ≤ N, 1 ≤ Ci1 ≤ Ci2 ≤ 100 000) which represent that towns Ai and Bi are connected with a road with ticket prices Ci1 and Ci2.

출력

In a single line output the smallest cost of travel.

제한

서브태스크

번호배점제한
120

2 ≤ N ≤ 2000

225

Each town will be directly connected with at most two other towns.

365

No additional constraints.

예제 입력 1

4
1 2 3 5
1 3 2 4
2 4 1 3

예제 출력 1

10

Fabijan first travels from town 1 to town 2 and it is optimal for him to buy a multi-pass ticket (5 euros) for the road which connects them. Then he travels from town 2 to town 3 via town 1. He already has a multi-pass ticket that takes him from 2 to 1 and he buys a single-pass ticket from town 1 to town 3 (2 euros). On his travels from town 3 to town 4 he buys another single-pass ticket that takes him from town 3 back to town 2 (2 euros) and after that buys a single-pass ticket that takes him from town 2 to town 4 (1 euro). In total, he spent 5 +たす 2 +たす 2 +たす 1 = 10 euros.

예제 입력 2

4
1 4 5 5
3 4 4 7
2 4 2 6

예제 출력 2

16

예제 입력 3

5
1 2 2 3
1 3 2 3
1 4 2 3
1 5 2 3

예제 출력 3

11

힌트

출처

Contest > Croatian Open Competition in Informatics > COCI 2019/2020 > Contest #5 4번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /