| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 | 256 MB | 16 | 5 | 1 | 25.000% |
Busy Beaver is visiting MIT, so he decided to have a tour around campus.
The campus consists of $N$ rooms and $N-1$ corridors between them. The rooms are enumerated consecutively from 1ドル$ to $N,ドル and the $i$-th corridor has a known length $w_i$ and can be traversed in both directions. The layout of campus is also such that between any two rooms, there is exactly one way to go from one to another through these corridors without going through any room twice. Define the level of a room to be the minimum number of corridors needed to get from the Great Dome (room 1ドル$) to this room. For instance, the Great Dome is level 0ドル,ドル and any room directly connected to it would be level 1ドル$. Let $k$ be the highest level of any room on campus, and denote $d(u, v)$ to be the length of the shortest path between rooms $u, v$.
Busy Beaver wants his tour to be interesting. Starting from the Great Dome (room 1ドル$), he wishes to visit a sequence of rooms $a_1, \dots, a_k$ such that for each 1ドル \leq i \leq k,ドル room $a_i$ is on level $i,ドル and for each 1ドル \leq i < k,ドル rooms $a_i, a_{i+1}$ are not connected by a corridor. As Busy Beaver is busy as usual, he also wants to minimize the total distance of the tour, which is $$d(1, a_1) + d(a_1, a_2) + \dots + d(a_{k-1}, a_k).$$
Since the MIT campus is very complex, Busy Beaver needs your help to plan out his tour. Help him find out the minimum length of an interesting tour.
The first line consists of a single integer $N$ (2ドル \le N \le 2 \cdot 10^5$) --- the number of rooms at the MIT campus.
Each of the next $N-1$ lines contains three integers $u,ドル $v,ドル $w$ (1ドル \le u,v \le N,ドル $u \neq v,ドル 1ドル \le w \le 10^7$) --- a corridor between rooms $u$ and $v$ with the length $w$.
It is guaranteed that there is exactly one simple path between any two rooms, and that at least one interesting tour exists.
Output a single integer, the minimal distance of an interesting MIT tour.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 15 | $N \le 10^3$. |
| 2 | 25 | $N \le 10^5$ and the maximum level of any room satisfies $k \leq 100$. |
| 3 | 60 | No additional constraints. |
3 1 2 1 1 3 1
1
5 1 2 3 1 3 1 3 4 2 3 5 3
9
In the first test case, there are two possible interesting tours:
They both obtain the minimum possible length of 1ドル,ドル which is the answer for this case.
In the second test case, notice that both rooms of level 2ドル$ are connected to room 3ドル$. Therefore, no interesting tour can have $a_1 = 3,ドル or otherwise it will violate the condition that $a_1, a_2$ are not connected by a corridor. Therefore, there are two possible interesting tours:
Therefore, the minimum length of an interesting tour in this case is 9ドル$.
University > MIT > M(IT)^2 > M(IT)^2 Winter 2025 Tournament > Advanced Round 2 3번