UVa 567:risk (Floyd)

Source: Internet
Author: User

Link:

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=508

Topic:

Risk is a board game in which several opposing-players to attempt the world. The gameboard consists of a world map broken up into hypothetical countries. During a player ' s turn, armies stationed in one country are only allowed to attack only countries with which they share a Common border. Upon conquest of that country, the armies could move into the newly conquered.

During The course, a player often engages in a sequence to conquests with the goal of transferring a large mass of Armies from some starting country to a destination country. Typically, one chooses the intervening countries so as to minimize "total number of countries," need to be conquered . Given a description of the gameboard with countries each with between 1 and connections to other countries, your TAS K is to write a function that takes a starting country and a destination country and computes the minimum number of countr IES that must is conquered to reach the destination. You don't need to output the sequence of countries, just the number of countries to be conquered including the Destinatio N. For example, if starting and destination countries are neighbors, then your program should return one.

The following connection diagram illustrates.

Input

Input to your program would consist of a series of country configuration test sets. Each test set would consist of a board description on lines 1 through 19. The representation avoids listing every national boundary twice from only listing the fact I Country I borders Country J When I < J. Thus, the Ith line, where I is less than, contains a integer X indicating how many ' ' higher-numbered ' countries borders with country I, then X distinct integers J greater than I and don't exceeding, each describing a boundary between Countries I and J. Of the test set contains a single integer (

N lines each contain exactly two integers (

There can be multiple test sets in the input file; Your program should continue reading and processing until the "end of" file. There'll be on least one path between any two given countries in every country.

Output

For each input set, your program should print the following message ' test set #T ' where T is the number of the ' Test set S Tarting with 1 (left-justified starting in column 11).

The next NT lines each would contain to the corresponding test in the test set-that is, the minimum number of Countries to conquer. The test result line should contain the "Start country code A right-justified in columns 1 and 2; The string ' to ' in columns 3 to 6; The destination country code B right-justified in columns 7 and 8; The string ': ' in columns 9 and 10; And a single integer indicating the minimum number of moves required to traverse from country A to country B in the test s Et left-justified starting in column 11. Following all result lines of the each input set, the your program should print a single blank line.

Sample Input

1 3
2 3 4 3 4 5 6 1 6 1 7 2 1 8 2 9 1 1 2
4
2
1
1
2 of
1 1 5 1
2 9/19
  
   16
4 2 3 5 6 1 4 3 4 5 5 2 6 7 2 7 8 2 9 1 9 1
10
   2
3
3
4
0
0
0 2 M 1 1 6 m (+))
1
8
4
7
2 16

  

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.