Simulation competition [treasure map]

Source: Internet
Author: User

Treas .*)

Background

Czy climbed onto the black mangrove tree and reached a strange place ......

Description

Czy found a strange treasure map. There are n vertices on the graph, and m are undirected edges. The distance between two pairs in the graph is marked as Dist. However, czy knows that this treasure map is true only when the figure is just a tree. If the treasure map is true, X, which has the largest Edge Weight mean after vertices x, is the place where the treasure is hidden. Calculate whether this is a real treasure map.

Format

The number t in the first row of the input data indicates the T group of data.

For each group of data, the first line is N, indicating the number of points on the treasure map.

In the next n rows, N numbers in each row indicate the distance between two nodes.

Output one or two rows. The first line "yes" or "no" indicates whether this is a real treasure map.

If it is a real treasure map, output a number in the second line to indicate which point is a treasure map.

Sample Input

2

3

0 7 9

7 0 2

9 2 0

3

0 2 7

2 0 9

7 9 0

Sample output

Yes

1

Yes

3

Example: the shape of the first tree is 1--2--3. The edge weights between 1 and 2 are 7, 2, and 3 are 2.

The shape of the second tree is 2--1--3. The Edge Weight between 2 and 3 is 7.

Data range

For 30% data, n <= 50, 1 <= the length of the edge on the tree <= 10 ^ 9.

For 50% data, n <= 600.

For 100% data, 1 <= n <= 2500, any 0 except 30% small data <= DIST [I] [J] <= 10 ^ 9, T <= 5

 

Run the minimal spanning tree regardless of whether it is a tree or not to calculate the dist2 Array under the MST condition. If it is a tree, it is clear that dist and dist2 are exactly the same. If they are different, this graph must not be a tree. In addition, Kruskal will be stuck. The second question is: how can this problem be solved in the first question?

Http://www.cnblogs.com/zhber/p/4035894.html

Simulation competition [treasure map]

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.