Game
시간 제한2초메모리 제한256 MB
간선을 하나씩 추가한 뒤, 특별 행성 0번부터 k-1번을 지나는 유향 사이클이 존재하는지 판별한다.
문제
After discovering planets, numbered from to , the Pharaohs have started to build a transportation system between them by one-way teleporters. Each teleporter has a starting planet and an ending planet. When a tourist uses a teleporter in the starting planet, the tourist is teleported to the ending planet. Note that the starting and ending planet of a teleporter may be the same. A teleporter with its starting planet and ending planet is denoted by .
To encourage widespread use of the teleportation system, the Pharaohs have created a game that can be played by tourists while travelling with the transportation system. A tourist can start the game from any planet. The planets () are called special planets. Every time a tourist enters a special planet, the tourist gets an stamp.
Currently, for each (), there is a teleporter . These teleporters are called starting teleporters.
New teleporters are added one by one. As new teleporters are added, it may become possible for a tourist to get infinite number of stamps. To be precise, this happens when there is a sequence of planets satisfying the following conditions:
- For each (), there is a teleporter .
Note that a tourist can use starting teleporters and any teleporters that have been added so far.
Your task is to help the Pharaohs verify, after the addition of each teleporter, whether a tourist can get infinite number of stamps or not.
제한
For each call to the add_teleporter procedure:
- and
- There is no teleporter from the planet to the planet before adding the teleporter .
예제
이 문제는 공개된 예제가 없습니다.