Under construction

Still being built. Things may change

Succession

Interview

Time limit12sMemory limit1024 MB

Summary
Pick exactly K areas that form a connected subtree of the road tree to maximize total value, then count the ways to achieve that maximum modulo 1000000007.
Level

Medium6 of 10

Topics
Dynamic programming, Tree, DFS
Solved
No attempts yet

Problem

Vito ran many businesses in different areas of New York, from simple olive oil to more dangerous products. Competition was literally cut-throat, and Vito was most vulnerable while traveling. So he had some of the roads he used sanitized, so that he could travel between any two of his areas using only sanitized roads. Sanitization was extremely costly, so his Consigliere sanitized the minimum number of roads needed.

Vito grew old and handed the reins to his son Michael. The Capos wanted a part of the business too, so Michael will pick exactly KK areas for himself, and the Capos keep the rest. Michael worked out the business value of each area, including some loss-making areas. He wants to pick his KK areas so that the total business value is maximized and he can travel between any two of his areas using only sanitized roads. He also does not want to pass through an area that is not his. In other words, the chosen areas must form a connected part of the road network.

Find the highest possible total business value. Also find the number of ways to achieve it, modulo 1000000007.

Input

The first line contains TT, the number of test cases. The first line of each test case contains three space-separated integers NN, KK, and RR, where NN is the number of areas, KK is the number of areas Michael picks, and RR is the number of sanitized roads. The next line contains NN integers, where the ii-th integer is the business value of area ii. Each of the next RR lines contains two space-separated integers from and to (both 0-based), meaning there is a two-way sanitized road between areas from and to.

Output

For each test case, print one line with two space-separated integers. The first is the highest possible business value. The second is the number of ways to achieve it, modulo 1000000007.

Constraints

  • 1≤T≤1001 \le T \le 100
  • 1≤K≤N≤1001 \le K \le N \le 100
  • Each business value is between −1000-1000 and 10001000, inclusive.
  • 0≤from,to<N0 \le from, to < N, and fromfrom and toto are distinct.
  • No two roads connect the same pair of areas.
  • The roads connect every pair of areas, and removing any single road disconnects some pair of areas.

Examples1

  1. Example 1

    Input
    1
    2 1 1
    10 10
    0 1
    
    Expected output
    10 2