Pro.ID21604 TitleMissile Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21604 AC10 Submit60 Ratio16.67% 时间&空间限制描述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 ( M ≤ N ) 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 ≤ N ≤ K, 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 ≤ M ≤ K, 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 ( M ≤ N ) 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 ≤ N ≤ K, 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 ≤ M ≤ K, 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 Sample Output 1 Source 样例输入2 样例输出1 作者 |