21604_Missile

2022-5-16 18:19| 发布者: Hocassian| 查看: 27| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505681038600-Problem List-采集的数据-后羿采集器.html

Pro.ID

21604

Title

Missile

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21604

AC

10

Submit

60

Ratio

16.67%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Given a complete undirected graph G = (V, E) representing a map of a continent, each node represents a city. There are two countries, called A and B, in the continent. Country A has N cities and country B has M cities. Country A is a big country ( MN ) and recently the scientists of country A invent a new weapon --- A Crotalid Missile (Short for ACM). This missile is so powerful that it can destroy one city. President of country A has ordered that every city of his country should be armed with one missile. Of course president of country B knows this news because of the capable spies of his country. He thinks that his country is in dangerous and requires the intelligent scientists to build a missile defense system to prevent the future attack from country A. This defense system must be reliable and effective. But before building the system, the scientists need to know how fast the system should be expected to react to the missile attack. Hence, the minimum time for country A needed to destroy all cities of country B is required to calculated, by you, the most intelligent member of the scientists of country B.

    输入

    Input may consist of several test data sets. For each data set, it can be format as below:

    First comes one line with one integer K, 2 ≤ K ≤ 100, the number of nodes in the graph.

    Then comes K lines, each contains K integer separating with one space, representing the edges of the complete graph. The number of the matrix[i][j] represents the minutes needed by the missile flying from city i to city j. Every integer is between [1, 100]. The matrix is symmetry.

    Then comes one line with one integer N, 1 ≤ NK, the number of cities of country A.

    N lines follow, each line contains one integer which is between [1, K], representing the city number of country A. The integers are distinct.

    Then comes one line with one integer M, 1 ≤ MK, the number of cities of country B.

    M lines follow, each line contains one integer which is between [1, K], representing the city number of country B. The integers are distinct.

    You can assume all input data sets are valid.

    Input is ended by K = 0.

    输出

    Description

    Given a complete undirected graph G = (V, E) representing a map of a continent, each node represents a city. There are two countries, called A and B, in the continent. Country A has N cities and country B has M cities. Country A is a big country ( MN ) and recently the scientists of country A invent a new weapon --- A Crotalid Missile (Short for ACM). This missile is so powerful that it can destroy one city. President of country A has ordered that every city of his country should be armed with one missile. Of course president of country B knows this news because of the capable spies of his country. He thinks that his country is in dangerous and requires the intelligent scientists to build a missile defense system to prevent the future attack from country A. This defense system must be reliable and effective. But before building the system, the scientists need to know how fast the system should be expected to react to the missile attack. Hence, the minimum time for country A needed to destroy all cities of country B is required to calculated, by you, the most intelligent member of the scientists of country B.

    Input

    Input may consist of several test data sets. For each data set, it can be format as below:

    First comes one line with one integer K, 2 ≤ K ≤ 100, the number of nodes in the graph.

    Then comes K lines, each contains K integer separating with one space, representing the edges of the complete graph. The number of the matrix[i][j] represents the minutes needed by the missile flying from city i to city j. Every integer is between [1, 100]. The matrix is symmetry.

    Then comes one line with one integer N, 1 ≤ NK, the number of cities of country A.

    N lines follow, each line contains one integer which is between [1, K], representing the city number of country A. The integers are distinct.

    Then comes one line with one integer M, 1 ≤ MK, the number of cities of country B.

    M lines follow, each line contains one integer which is between [1, K], representing the city number of country B. The integers are distinct.

    You can assume all input data sets are valid.

    Input is ended by K = 0.

    Output

    For each data set, just output one integer in one line, representing the minimum time measured in minutes that the missile would destroy all cities of country B.

    Sample Input

    2
    0 1
    1 0
    1
    2
    1
    1
    3
    0 2 1
    2 0 10
    1 10 0
    2
    2 3
    1
    1
    0

    Sample Output

    1
    1

    Source

    样例输入

    2
    0 1
    1 0
    1
    2
    1
    1
    3
    0 2 1
    2 0 10
    1 10 0
    2
    2 3
    1
    1
    0

    样例输出

    1
    1

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部