Graph Cuts

시간 제한4초메모리 제한2048 MB

요약
삽입과 삭제로 집합이 바뀌는 동안, 각 질의마다 절단 경계를 지나는 간선 하나를 출력하고 그래프에서 지우거나, 그런 간선이 없음을 판정한다.
난이도

보통10점 중 6점

유형
그래프, 해시맵, 구현
정답자
아직 제출이 없습니다

문제

You are given an undirected graph without multiple edges or self-loops. You also have a set of its vertices UU that is initially empty. Your task is to answer queries of the following form.

  1. "+ vv". Add vertex vv to UU. It is guaranteed that v∉Uv \not\in U.
  2. "- vv". Remove vertex vv from UU. It is guaranteed that v∈Uv \in U.
  3. "?". Find an edge such that exactly one of its endpoints is in UU and remove it from the graph, or determine that there are no such edges. If there are multiple edges that fulfill this property, you can choose any one of them.

입력

The first line contains two integers nn and mm: the numbers of vertices and edges in the graph correspondingly (0≤n,m≤1050 \le n, m \leq 10^5). Each of the next mm lines contains two integers uu and vv: the endpoints of a bidirectional edge (1≤u,v≤n1 \leq u, v \leq n). It is guaranteed that there are no multiple edges and no self-loops in the graph.

The next line contains a single integer qq, the number of queries (0≤q≤1050 \le q \leq 10^5). The next qq lines contain queries in the format described above (1≤v≤n1 \le v \le n in the queries).

출력

For each query of the third type, your program should either print a number of the found edge in the order it was presented in the input, or print 00 if such an edge does not exist.

예제1

  1. 예제 1

    입력
    4 5
    1 2
    1 3
    1 4
    2 3
    2 4
    10
    + 1
    + 2
    ?
    ?
    ?
    ?
    ?
    - 2
    ?
    ?
    
    예상 출력
    5
    4
    3
    2
    0
    1
    0