Thieves and Prisons
시간 제한1초메모리 제한1024 MB
도둑 n명과 감옥 k개에 대해 붙잡힘과 석방 사건이 순서대로 주어질 때, 각 사건에 감옥 번호를 배정하거나 불가능함을 판정한다.
문제
There are thieves and 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 events of the form "thief has been caught" or "thief 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 , and : the number of thieves, prisons and events. The thieves and prisons are numbered and .
After this, there are lines that describe the events. Each event is "C " (thief has been caught) or "O " (thief opens the gate of a prison).
출력
Print a valid prison assignment that consists of integers: for every event the corresponding prison. If there are no solutions, print "IMPOSSIBLE".