一道dfs的题,不会优化,求教怎么优化
Long time ago, there were n cities in a country named ABP(A Beautiful Place).There was an interconnected network of trade routes among some of the cities. Realized that a powerful nation was based on good connection among the cities, the King of the country make a decision to set up a freeway network, which is also known as the Silk Road Project. The king selected k wealthy cities to take the lead in setting up the freeway network. Here are the Silk Road Project’s rules: 1. In order to save costs, the freeway must be built at the basis on the original routes. 2. Every two selected cities can connect to each other by the freeway. 3. There will be no more than 10 unselected cities. Notice that there is NO city has the trade route connect to itself, and no more than ONE direct trade route between two cities.
输入格式
The input consists of T test cases. T is given in the first line of the input file.
Each test case begins with the first line containing three integer, n, m, k. n for n cities(2 <= n <= 100), m for m trade routes, k for k selected cities.
The second line for each case contains k positive integers representing the selected cities, numbered from 1 to n.
The following m lines contain triples of integers ai, bi, vi(1<=vi<=10000) . Where vi for the cost of building a freeway between ai and bi city.
There is an empty line after each test case.
输出格式
For each testcase, outputs should be set in one line.
If the Silk Road Project can be worked out, a positive integer should be printed to show the minimum cost.
Otherwise, the output should be “No solution!”.
输入样例
2
3 2 2
1 2
1 2 3
2 3 4
3 2 2
1 3
1 2 3
2 3 4
输出样例
3
7