[Daily learning] [floyd] codevs1077 multi-source shortest answer, floydcodevs1077

Source: Internet
Author: User

[Daily learning] [floyd] codevs1077 multi-source shortest answer, floydcodevs1077

Source: codevs1077

Description Description

N points (n <= 100) are known, and the square matrix of n x n is given. a [I, j] indicates the direct distance from vertex I to vertex j.

Now we have Q queries. Each query has two positive integers, a and B. This allows you to find the shortest distance between a and B.

Meet a [I, j] = a [j, I];

Input description Input Description

The first line is a positive integer n, And the next n rows have n positive integers in each line, satisfying the conditions of a [I, I] = 0, and then a row of Q, followed by a row of Q, each row has two integers, a and B.

Output description Output Description

A total of Q rows. Each row has an integer.

Sample Input Sample Input

3

0 1 1

1 0 3

1 3 0

1

2 3

Sample output Sample Output

2

Data range and prompt Data Size & Hint

N <= 100, Q may be very large. G [I] [j] All> = 0

Use the flyod Algorithm

If you use C/C ++, note that due to the large input data, using cin and cout may cause program timeout. Use scanf and printf for input and output.


Such a question is a raw floyd, so it is used as a template.

Floyd is actually the idea of dynamic planning. Each cycle is equivalent to finding the Shortest Path of the first k points.

Directly run the Code:



-The teacher, so the Evangelist is also confused.

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.