QOJ.ac

QOJ

Límite de tiempo: 3 s Límite de memoria: 512 MB Puntuación total: 100

#837. Giant Penguin

Estadísticas

Pengsoo is a well-known giant Korean penguin. He is very rude and loves singing.

This time, Pengsoo is performing graph queries.

He has a connected undirected graph, where each vertex lies on at most $k$ vertex-simple cycles.

He wants to answer two types of queries.

  • Mark some vertex $v$.
  • Find the closest marked vertex to the vertex $v$ (it is guaranteed that when the query of this type is asked, there is at least one marked vertex).

Pengsoo is very lazy, and has decided to take a nap, so he asks you to perform these queries. If you do not succeed by the time he wakes up, he will bully you, so act quickly!

Input

The first line of input contains three integers $n, m, k$ ($1 \le n \le 100\,000$, $n - 1 \le m \le 200\,000$, $0 \le k \le 10$): the number of vertices, edges, and largest number of vertex-simple cycles that may pass through one vertex.

The next $m$ lines contain the description of edges. The $i$-th of them contain two integers $u_i, v_i$ ($1 \le u_i, v_i \le n, u_i \neq v_i$), denoting an edge between vertices $u_i$ and $v_i$.

It is guaranteed that there are no multiple edges, the graph is connected, and each vertex lies on at most $k$ vertex-simple cycles.

The next line contains one integer $q$ ($1 \le q \le 200\,000$): the number of queries.

The next $q$ lines contain the description of queries. The $i$-th of them contain two integers $t_i, v_i$ ($1 \le t_i \le 2, 1 \le v_i \le n$).

If $t_i = 1$, mark the vertex $v_i$. It is guaranteed that this vertex was not marked before.

If $t_i = 2$, find the distance to the closest marked vertex from $v_i$. It is guaranteed that there is at least one marked vertex.

Output

For each query with $t_i = 2$, print the distance to the closest marked vertex.

Examples

Input 1

5 4 0
1 2
2 3
3 4
4 5
7
1 1
1 5
2 1
2 2
2 3
2 4
2 5

Output 1

0
1
2
1
0

Input 2

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

Output 2

2
2

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1549EditorialOpenNew Editorial for Problem #837xcx09022026-04-16 16:09:48View
#1546EditorialOpenNew Editorial for Problem #837robertfan2026-04-16 11:31:33View
#603Editorial Open集训队作业 解题报告 by 祁沐笛Qingyu2026-01-02 22:56:58 Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.