Codeforces Round 260 (Div. 2)
E
Civilization
Codeforces
未评级
原题
← D→
翻译中…

Andrew plays a game called "Civilization". Dima helps him.

翻译中…

The game has $*n*$ cities and $*m*$ bidirectional roads. The cities are numbered from $1$ to $*n*$. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities $*v*_{1}, *v*_{2}, ..., *v*_{*k*}$, that there is a road between any contiguous cities $*v*_{*i*}$ and $*v*_{*i* + 1}$ ($1 ≤ *i* < *k*$). The length of the described path equals to $(*k* - 1)$. We assume that two cities lie in the same region if and only if, there is a path connecting these two cities.

翻译中…

During the game events of two types take place:

翻译中…
  1. Andrew asks Dima about the length of the longest path in the region where city $*x*$ lies.
  2. Andrew asks Dima to merge the region where city $*x*$ lies with the region where city $*y*$ lies. If the cities lie in the same region, then no merging is needed. Otherwise, you need to merge the regions as follows: choose a city from the first region, a city from the second region and connect them by a road so as to minimize the length of the longest path in the resulting region. If there are multiple ways to do so, you are allowed to choose any of them.
翻译中…

Dima finds it hard to execute Andrew's queries, so he asks you to help him. Help Dima.

翻译中…

Input

翻译中…

The first line contains three integers $*n*$, $*m*$, $*q*$ ($1 ≤ *n* ≤ 3·10^{5}$; $0 ≤ *m* < *n*$; $1 ≤ *q* ≤ 3·10^{5}$) — the number of cities, the number of the roads we already have and the number of queries, correspondingly.

翻译中…

Each of the following $*m*$ lines contains two integers, $*a*_{*i*}$ and $*b*_{*i*}$ ($*a*_{*i*} ≠ *b*_{*i*};$ $1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*$). These numbers represent the road between cities $*a*_{*i*}$ and $*b*_{*i*}$. There can be at most one road between two cities.

翻译中…

Each of the following $*q*$ lines contains one of the two events in the following format:

翻译中…
  • $1$ $*x*_{*i*}$. It is the request Andrew gives to Dima to find the length of the maximum path in the region that contains city $*x*_{*i*}$ ($1 ≤ *x*_{*i*} ≤ *n*$).
  • $2$ $*x*_{*i*}$ $*y*_{*i*}$. It is the request Andrew gives to Dima to merge the region that contains city $*x*_{*i*}$ and the region that contains city $*y*_{*i*}$ ($1 ≤ *x*_{*i*}, *y*_{*i*} ≤ *n*$). Note, that $*x*_{*i*}$ can be equal to $*y*_{*i*}$.
翻译中…

Output

翻译中…

For each event of the first type print the answer on a separate line.

翻译中…

样例

Input #1
6 0 6
2 1 2
2 3 4
2 5 6
2 3 2
2 5 3
1 1
Output #1
4
InputCopy OutputCopy
题目信息
题号
456E
时间限制
1 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。