[Usaco 2008 Open] clear and present danger treasure path [shortest path] [WATER]

Source: Internet
Author: User
Description Farmer John is driving a boat to sail at niulebi sea. there are N (1 ≤ n ≤ 100) Islands at sea, numbered from 1 to n. john departs from island 1 and finally to island n. according to a treasure map, if the island that passes through his journey appears AI, A2 ,..., A sequence like am (2 ≤ m ≤ 10000) (not necessarily adjacent) can finally find the ancient treasure. however, there are piracy in niulebihai. john knows the probability that a route between any two islands is stolen from Shanghai. He describes it with a dangerous index dij (0 ≤ dij ≤ 100000. he hoped that the sum of the route risk indexes for his treasure hunt would be the smallest. so what is the minimum risk index when a treasure is found? Input N and m in row 1st, and then an integer in Row M indicates sequence A, and then input a matrix of nxn, indicating the risk index of the routes between two islands. data guarantee dij = DJI, DiI = 0. minimum output risk index and. sample input3 4
1
2
1
3
0 5 1
5 0 2
1 2 0

Input details:

There are 3 islands and the treasure map requires Farmer John
Visit a sequence of 4 islands in order: Island 1, Island 2, Island
1 again, and finally island 3. The danger ratings of the paths are
Given: The paths (1, 2); (2, 3); (3, 1) and the reverse paths have
Danger ratings of 5, 2, and 1, respectively.


Sample output7

Output details:

He can get the treasure with a total danger of 7 by traveling in
The sequence of Islands 1, 3, 2, 3, 1, and 3. The cow map's Requirement
(1, 2, 1, and 3) is satisfied by this route. We avoid the path
Between Islands 1 and 2 because it has a large danger rating.

Question:

Super Short Circuit Problem =

By the way, spfa, Dijkstra, and Floyd are all practiced.

Attached template;

[Usaco 2008 Open] clear and present danger treasure path [shortest path] [WATER]

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.