"Daily Learning" "Floyd" codevs1077 multi-source Shortest path

Source: Internet
Author: User

Topic Source codevs1077

Title Description Description

Known n points (n<=100), give you a n*n square, a[i,j] represents the direct distance from the point I to the J point.

There are now Q queries, each asking two positive integers, a and B, allowing you to find the shortest distance between A and B.

Meet A[i,j]=a[j,i];

Enter a description input Description

The first line is a positive integer n, followed by n rows of n positive integers per row, satisfies a[i,i]=0, and then lines a Q, followed by Q line, two positive integers a and b per line.

outputs description output Description

A total of Q lines, one integer per line.

sample input to sample

3

0 1 1

1 0 3

1 3 0

1

2 3

Sample output Sample outputs

2

data size & Hint

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

Please use the FLYOD algorithm

Please note that with C + +: Because of the large input data, using CIN and cout causes the program to time out. Please use scanf and printf for input and output.


A topic like this is a bare Floyd, so call him up as a template.

Floyd is actually the idea of dynamic planning, each cycle is equivalent to the selection of the first k points of the shortest.

Directly on the code:



--the teacher, so preach bred doubts also.

"Daily Learning" "Floyd" codevs1077 multi-source Shortest path

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.