Dungeon of Darkness

시간 제한1초메모리 제한1024 MB

요약
양쪽에 기호가 표시된 n개의 문이 잇는 방들로 이루어진 던전에서 입구에서 현자까지 5n번 이하로 문을 통과해 이동한다.
난이도

보통10점 중 7점

유형
그래프, DFS
정답자
아직 제출이 없습니다

문제

In his great quest to rescue princess Zelda and protect the kingdom of Hyrule from the clutches of the evil Ganondorf, you, the hero, have arrived in the Lost Woods to rescue an ancient sage. The spirits of the woods have decided to test your wits in a magic-infused dungeon. The dungeon consists of nn doors connecting two distinct rooms, each door marked by a glowing symbol on both sides (to simplify, each symbol is a number from 11 to nn). Each room is shrouded in complete darkness, making you unable to see anything other than the symbols. You enter the dungeon through a magic door that disappears upon entry, and the sage waits for you after door nn.

At the beginning of your quest, as well as every time you pass through a door, you see the symbols of all the doors that lead to and from the room which you are in. You also need to be quick of course, as the forces of Ganondorf do not wait. Going through doors a total of over 5⋅n5 \cdot n times will be too slow and will cause Hyrule to fall to ruin!

예제2

  1. 예제 1

    입력
    3
    2
    1 2
    
    1
    1
    
    2
    1 2
    
    2
    2 3
    
    
    예상 출력
    
    
    
    1
    
    
    1
    
    
    2
    
    
    3
    
  2. 예제 2

    입력
    5
    3
    1 2 3
    
    2
    1 3
    
    3
    1 2 3
    
    3
    2 4 5
    
    1
    4
    
    3
    2 4 5
    
    
    예상 출력
    
    
    
    1
    
    
    3
    
    
    2
    
    
    4
    
    
    4
    
    
    5