CF455C.Civilization

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

The game has nn cities and mm bidirectional roads. The cities are numbered from 11 to nn . 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 v1,v2,...,vkv_{1},v_{2},...,v_{k} , that there is a road between any contiguous cities viv_{i} and vi+1v_{i+1} ( 1<=i<k1<=i<k ). The length of the described path equals to (k1)(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 xx lies.
  2. Andrew asks Dima to merge the region where city xx lies with the region where city yy 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 nn , mm , qq ( 1<=n<=31051<=n<=3·10^{5} ; 0<=m<n0<=m<n ; 1<=q<=31051<=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 mm lines contains two integers, aia_{i} and bib_{i} ( aibi;a_{i}≠b_{i}; 1<=ai,bi<=n1<=a_{i},b_{i}<=n ). These numbers represent the road between cities aia_{i} and bib_{i} . There can be at most one road between two cities.

Each of the following qq lines contains one of the two events in the following format:

  • 11 xix_{i} . It is the request Andrew gives to Dima to find the length of the maximum path in the region that contains city xix_{i} ( 1<=xi<=n1<=x_{i}<=n ).
  • 22 xix_{i} yiy_{i} . It is the request Andrew gives to Dima to merge the region that contains city xix_{i} and the region that contains city yiy_{i} ( 1<=xi,yi<=n1<=x_{i},y_{i}<=n ). Note, that xix_{i} can be equal to yiy_{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
    
首页