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

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

Thieves and Prisons

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

요약
도둑 n명과 감옥 k개에 대해 붙잡힘과 석방 사건이 순서대로 주어질 때, 각 사건에 감옥 번호를 배정하거나 불가능함을 판정한다.
난이도

보통10점 중 7점

유형
그리디, 유니온 파인드, 구현, 시뮬레이션
정답자
아직 제출이 없습니다

문제

There are nn thieves and kk prisons. A thief is either on the run or caught in a prison. Initially all thieves are on the run.

A thief who is on the run can be caught by the police, and then ends up in one of the prisons. A thief who is on the run can also open the gate of a prison. Then every thief in that prison is released from the prison. It would be pointless to open the gate of an empty prison, so that never happens.

You are given a list of mm events of the form "thief xx has been caught" or "thief xx has opened the gate of a prison". Your task is to find a prison assignment that corresponds to the events, or determine that it is not possible.

입력

The first input line has three integers nn, kk and mm: the number of thieves, prisons and events. The thieves and prisons are numbered 1,2,…,n1,2,\dots,n and 1,2,…,k1,2,\dots,k.

After this, there are mm lines that describe the events. Each event is "C xx" (thief xx has been caught) or "O xx" (thief xx opens the gate of a prison).

출력

Print a valid prison assignment that consists of mm integers: for every event the corresponding prison. If there are no solutions, print "IMPOSSIBLE".

예제2

  1. 예제 1

    입력
    3 2 5
    C 1
    C 2
    O 3
    O 2
    C 1
    
    예상 출력
    1 2 2 1 1
    
  2. 예제 2

    입력
    1 1 1
    O 1
    
    예상 출력
    IMPOSSIBLE