RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00551

Putovanje

Unrated 레이팅 미적용
난이도
1s
시간 제한
512MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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 sing\(le-pa\)ss ticket which costs \(C@@RISE_MATH_BLOCK_0@@i\)2 euros. For
each road, Fabijan can decide to buy a sing\(le-pa\)ss ticket each time he needs to traverse that road or he
might opt to buy a mul\(ti-pa\)ss 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.

제약

Subtask
Score
Constraints
1
20
\(2 \le N \le 2000\)
2
25
Each town will be directly connected with at most two other towns.
3
65
No additional constraints.

입력 형식

The first line contains an integer \(N\) (\(2 \le N \le 200\,000\)) from task description.
In \(i-th\) of the next (\(N - 1\)) lines there are four integers \(A_{i}\), \(B_{i}\), \(C_{i}\){1}, \(C_{i}\) (\(1 \le A_{i}\), \(B_{i} \le N\), \(1 \le C_{i}\){1} ≤\(C_{i}\)
100 000) which represent that towns \(A_{i}\) and \(B_{i}\) are connected with a road with ticket prices \(C_{i}\){1} and \(C_{i}\).

출력 형식

In a single line output the smallest cost of travel.

예제 1
입력
4
1 2 3 5
1 3 2 4
2 4 1 3
출력
10
예제 2
입력
4
1 4 5 5
3 4 4 7
2 4 2 6
출력
16
예제 3
입력
5
1 2 2 3
1 3 2 3
1 4 2 3
1 5 2 3
출력
11
설명

Clarification of the first example:
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.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2019/2020 Contest 5

평가 및 의견

Putovanje

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Putovanje

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8