benchmarks.wiki / Public workspace

Humanity's Last Code Exam / 2021_B / Dungeon Crawler

Problem

Answer published by the source. Consult the official source to check your work against its answer.

platform

atcoder

question content

# Problem Statement 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 n rooms connected by exactly n1 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 q different scenarios that Alice and Bob wish to examine. In the i i -th scenario, the player starts in room si s_i , the key is in room ki k_i , and the trap is in room ti t_i . For each scenario, compute the minimum amount of time needed to explore the entire dungeon without getting trapped. ## Input The first line of input contains two integers n n and q q , where n n (3 ≤ n n ≤ 2000) is the number of rooms and q q (1 ≤ q q ≤ 200000) is the number of scenarios to consider. Rooms are numbered from 1 to n n . The next n1 n - 1 lines each contain three integers u u , v v , and w w indicating that there is a corridor between rooms u u and v v (1 ≤ u,v u, v n n , uv u \neq v ) that takes time w w (1 ≤ w w 109 10^9 ) to traverse. Then follow q q lines: the i i -th of these lines contains three distinct integers si s_i , ki k_i , and ti t_i (1 ≤ si,ki,ti s_i, k_i, t_i n n ) indicating the room where the player starts, the room with the key, and the room with the trap, respectively. ## Output 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." ## Sample Input 1
Plain-text mathematical notation (without MathML)
# Problem Statement

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 i-th scenario, the player starts in room s_(i), the key is in room k_(i), and the trap is in room t_(i). For each scenario, compute the minimum amount of time needed to explore the entire dungeon without getting trapped.

## Input

The first line of input contains two integers n and q, where n (3 ≤ n ≤ 2000) is the number of rooms and q (1 ≤ q ≤ 200000) 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 ≤ 10⁹) to traverse.

Then follow q lines: the i-th of these lines contains three distinct integers s_(i), k_(i), and t_(i) (1 ≤ s_(i),k_(i),t_(i) ≤ n) indicating the room where the player starts, the room with the key, and the room with the trap, respectively.

## Output

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."

## Sample Input 1
Original LaTeX notation
# Problem Statement

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 \( i \)-th scenario, the player starts in room \( s_i \), the key is in room \( k_i \), and the trap is in room \( t_i \). For each scenario, compute the minimum amount of time needed to explore the entire dungeon without getting trapped.

## Input

The first line of input contains two integers \( n \) and \( q \), where \( n \) (3 ≤ \( n \) ≤ 2000) is the number of rooms and \( q \) (1 ≤ \( q \) ≤ 200000) 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 \neq v \)) that takes time \( w \) (1 ≤ \( w \) ≤ \( 10^9 \)) to traverse.

Then follow \( q \) lines: the \( i \)-th of these lines contains three distinct integers \( s_i \), \( k_i \), and \( t_i \) (1 ≤ \( s_i, k_i, t_i \) ≤ \( n \)) indicating the room where the player starts, the room with the key, and the room with the trap, respectively.

## Output

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."

## Sample Input 1

Code

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

## Sample Output 1

Code

15
17
impossible
12

## Sample Input 2

Code

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

## Sample Output 2

Code

11
impossible
10
10

question title

Dungeon Crawler

Discussion

Discussion

No discussion posts on this page yet. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

Source and history

Official source

initial import