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

26131번 - Dungeon Crawler 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB249482423.529%

문제

Alice and Bob are in charge of testing a new escape room! In this escape room, customers are trapped in a dungeon and have to explore the entire area. The dungeon consists of n rooms connected by exactly n−1 corridors. It is possible to travel between any pair of rooms using these corridors.

Two of the dungeon rooms are special. One of these rooms contains a protective idol known as the “helix key.” A different room contains a nasty “dome trap,” which prevents the player from moving once activated. Entering the room with the trap before acquiring the key will result in the player being trapped in the dungeon forever. The player cannot start in the same room as the key or the trap.

There are q different scenarios that Alice and Bob wish to examine. In the ith scenario, the player starts in room si, the key is in room ki, and the trap is in room ti. For each scenario, compute the minimum amount of time needed to explore the entire dungeon without getting trapped.

입력

The first line of input contains two integers n and q, where n (3 ≤ n ≤ 2 000) is the number of rooms and q (1 ≤ q ≤ 200 000) is the number of scenarios to consider. Rooms are numbered from 1 to n. The next n − 1 lines each contain three integers u, v, and w indicating that there is a corridor between rooms u and v (1 ≤ u, v ≤ n, u ≠ v) that takes time w (1 ≤ w ≤ 109) to traverse.

Then follow q lines: the ith of these lines contains three distinct integers si, ki, and ti (1 ≤ si, ki, ti ≤ n) indicating the room where the player starts, the room with the key, and the room with the trap, respectively.

출력

For each scenario, output the minimum amount of time needed to visit every room at least once. If it is impossible to visit every room at least once, output impossible.

제한

예제 입력 1

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

예제 출력 1

15
17
impossible
12

예제 입력 2

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

예제 출력 2

11
impossible
10
10

힌트

출처

ICPC > World Finals > ICPC World Finals 2021 B번

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

출처

대학교 대회

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

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