Graph Cuts
시간 제한4초메모리 제한2048 MB
삽입과 삭제로 집합이 바뀌는 동안, 각 질의마다 절단 경계를 지나는 간선 하나를 출력하고 그래프에서 지우거나, 그런 간선이 없음을 판정한다.
문제
You are given an undirected graph without multiple edges or self-loops. You also have a set of its vertices that is initially empty. Your task is to answer queries of the following form.
- "
+". Add vertex to . It is guaranteed that . - "
-". Remove vertex from . It is guaranteed that . - "
?". Find an edge such that exactly one of its endpoints is in 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 and : the numbers of vertices and edges in the graph correspondingly (). Each of the next lines contains two integers and : the endpoints of a bidirectional edge (). It is guaranteed that there are no multiple edges and no self-loops in the graph.
The next line contains a single integer , the number of queries (). The next lines contain queries in the format described above ( 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 if such an edge does not exist.