#P10350. Modernization of Bytetown

    ID: 12355 Type: Default 1000ms 256MiB

Modernization of Bytetown

Modernization of Bytetown

Bytetown is preparing for modernization. Initially, none of the n residents (numbered 1 through n) owns a computer. Over time, events occur that affect computer ownership. There are three types of events:

  • Donation event: + a b. A computer is donated to one of the two residents a or b. However, if a ≠ b then it is ambiguous which one receives the computer, with the only condition that it is given to someone who does not currently have a computer. (If a = b, then the donation is deterministic: resident a receives the computer.)
  • Malfunction event: - c. The computer of resident c breaks. It is guaranteed that at some point before this event the resident had received a computer (though Byteasar might not have been sure which donation gave it to him).
  • Query event: ? d. Using all information from the events processed so far, Byteasar must determine one of the following regarding resident d:
    • The resident definitely has a computer.
    • The resident definitely does not have a computer.
    • It is not possible to determine (i.e. uncertain).

The donation rule requires that the computer is always given to a resident who currently does not own a computer. Note that right before a malfunction event occurs, Byteasar might not be able to deduce with certainty who owned the computer; however, the malfunction event guarantees that in every valid assignment the specified resident must have had a computer at that time.

Your task is to process a sequence of events and answer every query correctly.

Input constraints and notes: It is guaranteed that at the moment of any donation event, a computer is given only to a resident who does not have one, and every malfunction event is valid. The ambiguity in donation events may result in several valid assignments of computers to residents. In such cases, a query should be answered "YES" if in every valid assignment the queried resident has a computer; similarly answer "NO" if in every valid assignment he does not have one; otherwise answer "NOT SURE".

Mathematical formulation:

Let the state of each resident i at any time be represented by a binary variable. For donation events with distinct candidates, if both candidates a and b currently have state 0, then the event leads to one of the two assignments:

(a,b)={(1,0)(0,1)(a, b) = \begin{cases} (1,0) \\ (0,1) \end{cases}

For malfunction events, if resident c had a computer (state 1) in every valid assignment (i.e. c had a computer inevitably) then his state becomes 0 after the event.

Your program should simulate these events and answer the queries accordingly.

inputFormat

The first line contains two integers n and m (1 ≤ n, m ≤ some small bound) representing the number of residents and the number of events respectively.

Each of the following m lines contains one event in one of the following formats:

  • + a b : Donation event. (If a = b then the donation is deterministic.)
  • - c : Malfunction event.
  • ? d : Query event.

It is guaranteed that every donation is given to a resident without a computer at that moment, and every malfunction event is valid.

outputFormat

For each query event, output a single line containing one of the three strings:

  • YES — if resident d definitely has a computer in every valid assignment.
  • NO — if resident d definitely does not have a computer in every valid assignment.
  • NOT SURE — if it is ambiguous whether resident d has a computer.

sample

2 3
+ 1 2
? 1
? 2
NOT SURE

NOT SURE

</p>