Civilization

题意翻译

给出一个由 $n$ 个点,$m$ 条边组成的森林,有 $q$ 组询问 1. 给出点 $x$,输出点 $x$所在的树的直径 2. 给出点 $x,y$,(如果 $x,y$ 在同一棵树中则忽略此操作)选择任意两点 $u,v$,使得 $u$ 跟 $x$ 在同一棵树中且 $v$ 跟 $y$ 在同一棵树中。将 $u,v$ 之间连一条边,使得连边后的到的新树的直径最小 ### 输入格式 第一行三个整数 $n,m,q$,分别表示 点的个数,边的个数和询问个数 接下来 $m$ 行,每行两个整数 $x,y$,表示有一条链接点 $x,y$ 的边 接下来 $q$ 行,每行表示一条操作 操作1:`1 x` 操作2:`2 x y` ### 输出格式 输出行数为操作1的个数 每行一个整数表示对应的操作一的答案 #### 说明与提示 $1 \le m < n \le 3\cdot 10^5$ $1 \le q \le 3 \cdot 10^5$ 感谢 @[_Wolverine](https://www.luogu.com.cn/user/120362) 提供的翻译

题目描述

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.

输入输出格式

输入格式


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} $ .

输出格式


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

输入输出样例

输入样例 #1

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

输出样例 #1

4