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

Sjekira

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

의견: 0

설명

Mirko is tired of his stressful CEO job in a we\(ll-kn\)own multinational software
company. With a golden parachute of several million dollars, he decided to live
a simple life and move to Gorski Kotar. However, winters in the remote village
he just moved in are tough. None of his neighbours were born after WWII, so he
is destined to chop firewood himself.
Today, he is going to chop his first trunk. Before chopping, he labels the parts of
the trunk which are small enough to fit in a fireplace, and measures their hardness.
Mirko is a programmer, so he notices that the parts and the connections between
them form a tree graph.
The damage on his axe resulting from cutting a connection on the trunk is equal to the sum of the
maximal hardnesses in the two connected components formed by cutting the connection.
Mirko has only one axe, so he wants the total damage to be as small as possible. He wants to know the
minimal total damage on the axe, if he cuts the whole trunk into single parts which fit in a fireplace.

제약

Subtask 1 (10 points): \(1 \le n \le 10\)

Subtask 2 (10 points): Parts \(i\) and \(i + 1\) (\(1 \le i \le n - 1\)) are directly connected.

Subtask 3 (30 points): \(1 \le n \le 1000\)

Subtask 4 (60 points): \(1 \le n \le 100\,000\)

입력 형식

The first line contains an integer \(n\), the number of parts. The parts are labeled by integers from 1 to \(n\).
The second line contains \(n\) integers \(t@@RISE_MATH_BLOCK_0@@i \le 10^{9}\)). The number \(t\)\(i\) is the hardness of the part labeled \(i\).
Each of the following \(n - 1\) lines contains two integers \(x\) and \(y\) (\(1 \le x\), \(y \le n\)) – labels of parts that are
directly connected.

출력 형식

Output the minimal total damage after \(n - 1\) cuts.

서브태스크
서브태스크점수설명

1

10점

\(1 \le n \le 10\)

2

10점

Parts \(i\) and \(i + 1\) (\(1 \le i \le n - 1\)) are directly connected.

3

30점

\(1 \le n \le 1000\)

4

60점

\(1 \le n \le 100\,000\)

예제 1
입력
3
1 2 3
1 2
2 3
출력
8
예제 2
입력
4
2 2 3 2
1 3
3 2
4 3
출력
15
예제 3
입력
5
5 2 3 1 4
2 1
3 1
2 4
2 5
출력
26
설명

Clarification of the first example:
There are two ways to cut this trunk. He can first cut the connection (1, 2), which causes 1 + 3 = 4
damage, and then cut the connection (2, 3), which causes 2 + 3 = 5 damage. The total damage is 9 in this
case.
Otherwise, he can first cut (2, 3), and then (1, 2). The total damage in that case (2 + 3) + (1 + 2) = 8.

문제 정보

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

출처 COCI 2020/2021 Contest 2

평가 및 의견

Sjekira

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

Log in to rate problems.

개별 의견

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

풀이 제출

Sjekira

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