Winter

 Uneori îmi spun: am să mor

atât de singuratecă-n mijlocul lor;
limba simplă a bucuriilor n-am învâțat;
am să mor ca o pasăre care prea mult a zburat,
dar n-a făcut cuib nicăieri.

― Oamenii ma uimesc, Magda Isafost


As of writing the informal statement, the winter just came and the statement was in season. Now, it is not winter anymore, so here is the formal statement instead:

You are given a connected graph with

nodes and edges. You are given

queries of the following types:

: Given node , set the state of the node
  • to frozen.
  • : Given , let
  • units of time pass by.
  • : Given node , answer if node
    • is currently frozen.

    Initially, no node is frozen.
    The graph has the following property:

    • If, at time
    , a node is frozen, then, at time , all neighbours of
    • become frozen.

    For each query of type

    , answer whether the node is currently frozen.

    Note:

    • If a node is already frozen, it remains unaffected after a type
  • query.
  • If, for a frozen node
  • , a neighbour of node is frozen at time , node remains unaffected at time
    • .

    Input Format

    • The first line of input contains three integers
    and
  • .
  • lines follow, the of which contains two integers and , representing there is an edge between nodes and
  • .
  • Then,
  • lines follow, the of which contains two integers and .
    If is or , it indicates that you must effectuate an update of the type with parameter . Otherwise, answer the query with parameter

    Output Format

    For each query of type

    , print if the queried node is frozen. Otherwise, print

    .

    You may print each character of the string in uppercase or lowercase (for example, the strings

    , , and

    will all be treated as identical).

    Constraints

  • , if the query type is or
  • .
  • , if the query type is
    • .

    Subtasks

    • Subtask 1 (10 points):
    • .
    • Subtask 2 (30 points): Each node in the given graph has at most two neighbours.
    • Subtask 3 (60 points): Original constraints.

    Sample Input 1

    6 6 6
    1 2
    2 3
    4 1
    5 4
    6 1
    6 5
    1 1
    3 1
    1 5
    2 1
    3 4
    3 3
    

    Sample Output 1

    YES
    YES
    NO
    

    Explanation

    Test Case

    : The graph looks like:

    • Query
    : Freeze the node
  • . The graph looks like:
  • Query
  • : Find the status of node . Since node is frozen, we print
  • .
  • Query
  • : Freeze the node
  • . The graph looks like:
  • Query
  • : unit of time passes. Before this, nodes and were frozen.
    After second, all the neighbours of node , i.e., nodes and , and all the neighbours of node , i.e., nodes and are frozen.
    Thus, after this query, the frozen nodes in the graph are and
  • . The graph looks like:
  • Query
  • : Find the status of node . Since node is frozen, we print
  • .
  • Query
  • : Find the status of node . Since node is not frozen, we print
    Previous
    Next Post »