CodeforcesRound #260 (div2) E solution report

Source: Internet
Author: User
AndrewplaysagamecalledCivilization. Dimahelpshim. Thegamehasncitiesandmbidirectionalroads. Thecitiesarenumberedfrom1ton. Adjust (unique) path, orthereisnopathatall.

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.

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

The game hasNCities andMBidirectional roads. The cities are numbered from 1N. 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 citiesV1 ,?V2 ,?...,?VK, That there is a road between any contiguous citiesVIAndVI? +? 1 (1? ≤?I? K). The length of the described path equals (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 cityXLies.
  2. Andrew asks Dima to merge the region where cityXLies with the region where cityYLies. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.