CF120F.Spiders

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

One day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he will glue all the spiders together and attach them to the ceiling. Besides, Petya knows that the lower the spiders will hang, the more mum is going to like it and then she won't throw his favourite toys away. Help Petya carry out the plan.

A spider consists of kk beads tied together by k1k-1 threads. Each thread connects two different beads, at that any pair of beads that make up a spider is either directly connected by a thread, or is connected via some chain of threads and beads.

Petya may glue spiders together directly gluing their beads. The length of each thread equals 1. The sizes of the beads can be neglected. That's why we can consider that gluing spiders happens by identifying some of the beads (see the picture). Besides, the construction resulting from the gluing process should also represent a spider, that is, it should have the given features.

After Petya glues all spiders together, he measures the length of the resulting toy. The distance between a pair of beads is identified as the total length of the threads that connect these two beads. The length of the resulting construction is the largest distance between all pairs of beads. Petya wants to make the spider whose length is as much as possible.

The picture two shows two spiders from the second sample. We can glue to the bead number 2 of the first spider the bead number 1 of the second spider. The threads in the spiders that form the sequence of threads of maximum lengths are highlighted on the picture.
翻译
一天,妈妈让 Petya 把他的玩具分类扔掉。彼佳发现了一整盒玩具蜘蛛。这些蜘蛛对他来说很珍贵,小男孩不想把它们扔掉。彼佳想出了一个狡猾的计划:他要把所有的蜘蛛粘在一起,然后固定在天花板上。此外,Petya 知道蜘蛛挂得越低,妈妈就会越喜欢,这样她就不会扔掉他最喜欢的玩具了。帮助 Petya 执行计划。

蜘蛛由 k 个珠子和 k - 1 根线组成。每根线连接两颗不同的珠子,因此组成蜘蛛的任何一对珠子要么直接由线连接,要么通过线和珠子的链条连接。

Petya 可以直接将蜘蛛和它们的珠子粘在一起。每根线的长度等于 1。珠子的大小可以忽略不计。因此,我们可以认为粘合蜘蛛是通过识别部分珠子来实现的(见图)。此外,粘合过程产生的结构也应该代表一只蜘蛛,也就是说,它应该具有给定的特征。

Petya 将所有蜘蛛粘在一起后,会测量玩具的长度。一对珠子之间的距离就是连接这两颗珠子的线的总长度。最终结构的长度就是所有珠子对之间的最大距离。Petya 希望制作的蜘蛛长度越长越好。


图 2 显示了第二个样本中的两只蜘蛛。我们可以在第一只蜘蛛的 2 号珠子上粘上第二只蜘蛛的 1 号珠子。图中突出显示了蜘蛛中形成最大长度线序的线。

输入格式

The first input file line contains one integer nn ( 1<=n<=1001<=n<=100 ) — the number of spiders. Next nn lines contain the descriptions of each spider: integer nin_{i} ( 2<=ni<=1002<=n_{i}<=100 ) — the number of beads, then ni1n_{i}-1 pairs of numbers denoting the numbers of the beads connected by threads. The beads that make up each spider are numbered from 1 to nin_{i} .
第一个输入文件行包含一个整数 n ( 1 ≤ n ≤ 100 ) - 蜘蛛的数量。接下来的 n 行包含对每个蜘蛛的描述:整数 ni ( 2 ≤ ni ≤ 100 ) --珠子的数量,然后是 ni - 1 对数字,表示用线连接的珠子的数量。组成每只蜘蛛的珠子编号从 1 到 ni 。

输出格式

Print a single number — the length of the required construction.
打印一个数字,即所需结构的长度。

输入输出样例

  • 输入#1

    1
    3 1 2 2 3
    

    输出#1

    2
    
  • 输入#2

    2
    3 1 2 1 3
    4 1 2 2 3 2 4
    

    输出#2

    4
    
  • 输入#3

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

    输出#3

    7
    
首页