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

31977번 - Minequake 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB74350.000%

문제

The fully autonomous microbreweries installed in the abandoned Dwarven mines of Moravia are truly a testament to the ingenuinity and craftsmanship of Dwarven engineering! Alas, sometimes earthquakes rattle the mines, leading to misaligned pipes and funnels spilling precious liquid on the floor. As the Exalted Warden of Brewery Safety it is your responsibility to turn off the machines in every hall in case of an earthquake.

Walking through tunnels takes time, so you will inevitably arrive late at many of the machines. This cannot be avoided, but you want to minimise the total amount of spilled liquid.

The Dwarven mines consist of $n$ halls connected by $n-1$ tunnels. The entire system is connected, so it is possible to get from any hall to any of the others. It takes 1ドル$ unit of time to traverse a tunnel. Switching off a machines and traversing a hall takes no time. In each hall, turning off the machines at time $t$ after the earthquake spills $t$ liters of liquid. There is exactly one earthquake, the earthquake affects all halls at the same time, and you may not switch off any machines before the earthquake. You can start in any of the halls.

In sample input 1ドル,ドル the mines look like this:

If you start in hall 2ドル$ and visit the rest of the halls in the order 2ドル,ドル 1ドル,ドル 2ドル,ドル 3ドル,ドル then you can switch off their machines at time 0ドル$ (in hall 2ドル$), time 1ドル$ (in hall 1ドル$), and time 3ドル$ (in hall 3ドル$). This wastes 0ドル+1+3=4$ liters of liquid in total. If instead you start in hall 1ドル$ and visit the halls in the order 1ドル,ドル 2ドル,ドル 3ドル,ドル the total amount of liquid wasted is 0ドル+1+2=3$ liters, which is better.

입력

The first line of input consists of the integer $n,ドル denoting the number of halls. We assume that the halls are numbered 1ドル,ドル $\ldots,ドル $n$. The next $n-1$ lines each contain two space-separated integers $u$ and $v$ with 1ドル\leq u < v \leq n,ドル meaning that there is a tunnel between hall $u$ and hall $v$.

출력

Print a single integer: the minimum amount of spilled liquid, in liters.

제한

We always have 1ドル\leq n\leq 10^5$.

서브태스크

번호배점제한
118

no hall has more than two tunnels

219

at most one hall has more than two tunnels

320

$n\leq 10$

421

$n\leq 1000$

522

No additional constraints

예제 입력 1

3
1 2
2 3

예제 출력 1

3

예제 입력 2

4
1 2
1 3
1 4

예제 출력 2

7

예제 입력 3

1

예제 출력 3

0

힌트

출처

Olympiad > Baltic Olympiad in Informatics > BOI 2023 D번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

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

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