아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Game

시간 제한2초메모리 제한256 MB

요약
간선을 하나씩 추가한 뒤, 특별 행성 0번부터 k-1번을 지나는 유향 사이클이 존재하는지 판별한다.
난이도

보통10점 중 7점

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

문제

After discovering nn planets, numbered from 00 to n−1n-1, 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 uu and ending planet vv is denoted by (u,v)(u,v).

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 0,1,…,k−10, 1, \ldots, k-1 (k≤nk \leq n) are called special planets. Every time a tourist enters a special planet, the tourist gets an stamp.

Currently, for each ii (0≤i≤k−20 \leq i \leq k-2), there is a teleporter (i,i+1)(i, i+1). These k−1k-1 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 w\[0],w\[1],…,w\[t]w\[0], w\[1], \ldots, w\[t] satisfying the following conditions:

  • 1≤t1 \leq t
  • 0≤w\[0]≤k−10 \leq w\[0] \leq k-1
  • w\[t]=w\[0]w\[t] = w\[0]
  • For each ii (0≤i≤t−10 \leq i \leq t-1), there is a teleporter (w\[i],w\[i+1])(w\[i], w\[i+1]).

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.

제한

  • 1≤n≤300,0001 \leq n \leq 300\\,000
  • 1≤m≤500,0001 \leq m \leq 500\\,000
  • 1≤k≤n1 \leq k \leq n

For each call to the add_teleporter procedure:

  • 0≤u≤n−10 \leq u \leq n-1 and 0≤v≤n−10 \leq v \leq n-1
  • There is no teleporter from the planet uu to the planet vv before adding the teleporter (u,v)(u,v).

예제

이 문제는 공개된 예제가 없습니다.