UVA 3027 corporative Network with right and check set,

Source: Internet
Author: User

Test instructions: An enterprise is going to buy some companies to make the interconnection between each enterprise, just start each company independent of each other

Given n companies, two operations

E I: Ask I to I it connection point the distance of the last company

I i J: Will I point to J Company, that is, J company is I Company's superior, distance for abs (I-J)%1000 (seemingly g++ not support abs,pe two rounds)

Idea: Conversion of test instructions on the line, first of all, the beginning of each company is independent, I operation is and check the merger operation, I this lesson tree and to J this tree,

E Operation requirements of the thing is I to I of the root node distance, first look at a no path compression direct violence method, (I thought not, because the data is very large)

Time is: 2222ms was despised by the system

And so on, now the examples given in the topic to direct the implementation of the I operation, and finally get the 3->1->2->4

So the result of E 3 is (3-1)%1000+ (2-1)%1000+ (4-2)%1000=5

And the check set itself is such a result, so directly from the child node to the root node to find the past, while looking for the distance

  

Path compression version, 66MS

UVA 3027 corporative Network with right and check set,

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.