Under construction

Still being built. Things may change

Tourism

Time limit2sMemory limit512 MB

Summary
Given a connected graph with city weights and a start city, find the maximum total weight of cities a walk from the start can visit without immediately reusing the road just taken.
Level

Medium6 of 10

Topics
Graph, DFS, Tree, Dynamic programming
Solved
No attempts yet

Problem

Da Vinci has a wide range of interests, including botany. He once planned a trip around Florence to study plant domestication and ecosystems. Florence has nn cities, and city ii has wiw_i plant species. Each of the mm bidirectional roads connects a pair of cities, and it is possible to travel between every pair of cities using these roads.

Da Vinci starts at city ss. He can move along one road at a time to an adjacent city. However, if he travels to city vv via the road u→vu \to v, he cannot immediately return to city uu on that same road. (Going back and forth on the same road is boring.)

Da Vinci wants to see as many plant species as possible, that is, maximize ∑visited iwi\sum_{\text{visited } i} w_i. He may visit a city more than once, but each city's species are counted only once. He does not care which city the trip ends in. What is the maximum number of plant species he can see during the tour?

Input

The first line contains the number of data sets KK (1≤K≤201 \le K \le 20), followed by the KK data sets.

The first line of each data set contains two integers nn and mm (1≤n,m≤10001 \le n, m \le 1000), separated by a space. The second line contains nn integers wiw_i (0≤wi≤1060 \le w_i \le 10^6). Each of the next mm lines contains two integers xjx_j and yjy_j (1≤xj,yj≤n1 \le x_j, y_j \le n), describing the jj-th road that connects cities xjx_j and yjy_j. The next line contains a single integer ss (1≤s≤n1 \le s \le n), the city where Da Vinci starts.

Any pair of cities can be reached from each other using these roads. No two roads connect the same pair of cities, and no road connects a city to itself.

Output

For each data set, print a line "Data Set x:" where xx is the data set number. On the next line, print the maximum number of plant species Da Vinci can see. Print a blank line after each data set.

Examples1

  1. Example 1

    Input
    2
    4 3
    1 2 3 4
    1 2
    1 3
    1 4
    2
    5 7
    2 2 8 6 9
    1 2
    1 3
    2 4
    3 2
    4 5
    2 5
    1 5
    2
    
    Expected output
    Data Set 1:
    7
    
    Data Set 2:
    27