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

32596번 - Buggy Blinkers 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 1024 MB31242379.310%

문제

Recently, your car underwent a software update. Now, if you use the blinkers too much, the car shuts down, reporting a "buffer overflow", whatever that means! On the bright side, you are now welcome at the Broken-down Automobile Preservation Convention (BAPC).

You found out late, so you have to drive there as quickly as possible! Still, of course, you have to obey all traffic rules. At each intersection, you should follow these rules, regardless of whether an intersection has roads in all directions or not:

  • When turning left (or right) at an intersection, the left (or right) blinker must be on.
  • When driving straight ahead, the blinkers must be off.
  • U-turns are not allowed, i.e. you are not allowed to turn back the way you came.

To play it safe with your blinkers, you decide you are going to activate them at most $k$ times. Luckily, you can still deactivate them at any time. This seems rather limiting, but you make one shrewd observation: as long as you keep your blinkers on (they do not turn off automatically), you can keep turning in the same direction.

The road network consists of intersections with roads between them. Roads always start and end in one of the four cardinal directions: north, east, south, or west. Furthermore, they never start and end at the same intersection. As an example, consider sample cases 1 through 3, visualized in Figure B.1. These samples only differ in their value of $k$.

Figure B.1: Visualization of the first, second, and third sample input.

To simplify navigation, you assume that each road can be traversed in the same amount of time, i.e. each road is considered to be of length 1ドル$. Find the shortest route from your current location to the BAPC, ensuring that you do not activate the blinkers more than $k$ times. From your current location, you can drive in any direction without using your blinkers.

입력

The input consists of:

  • One line with two integers $n$ and $k$ (1ドル \le n \le 5000,ドル 0ドル \le k \le 20$), the number of intersections and the number of times the blinkers can be activated.
  • $n$ lines, the $i$th of which contains four integers $v_i^{\text{N}},ドル $v_i^{\text{E}},ドル $v_i^{\text{S}},ドル and $v_i^{\text{W}}$ (0ドル \le v_i^{\text{N}}, v_i^{\text{E}}, v_i^{\text{S}}, v_i^{\text{W}} \le n$), the intersections that can be reached by taking the north, east, south, and west road from intersection $i,ドル or 0ドル$ to indicate that the road does not exist.

You start at intersection 1ドル,ドル and the BAPC is located at intersection $n$. Each intersection $i$ has at most one road to each other intersection $j$. If this road exists, then intersection $j$ has exactly one road to intersection $i$ as well.

출력

If it is possible to drive from intersection 1ドル$ to $n$ using the blinkers at most $k$ times, output the length of the shortest such route. Otherwise, output "impossible".

제한

예제 입력 1

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

예제 출력 1

3

예제 입력 2

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

예제 출력 2

4

예제 입력 3

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

예제 출력 3

impossible

예제 입력 4

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

예제 출력 4

impossible

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2024 B번

  • 문제를 만든 사람: Gijs Pennings
(追記) (追記ここまで)

출처

대학교 대회

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

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