Every other winter, LaLa helps her aunt, Aisha, harvest a crop native to the Biheiril Kingdom.
The crop can be modeled as a graph where an edge corresponds to a branch, a vertex to a joint, and a fruit with tastiness T_u grows on each joint u.
The cultivation of the crop can be divided into three phases.
LaLa's goal is to maximize the sum of tastiness of the fruits she has harvested. However, LaLa is not allowed to harvest fruits at two adjacent vertices, as it will stress and kill all the trunks directly connecting them.
Write a program that computes a set of fruits LaLa can harvest which has maximum possible sum of tastiness.
The input describes the state of a crop and is given in the following format:
N M
T_0 T_1 ⋯ T_N−1
u_0 v_0
u_1 v_1
⋮
u_M−1 v_M−1
K
x_0 y_0
x_1 y_1
⋮
x_K−1 y_K−1
where N is the number of joints, numbered from 0 to N−1, M the number of branches grown during the first phase, and the i-th branch connects the joints u_i and v_i for all integers 0≤i<M.
Consider the DFS-tree built over the cactus graph grown during the first phase where the DFS traversal starts at joint 0 and the order of the neighbors of each joints is given by the input order i.e. the traversal prioritizes branches given sooner in the input. Note that the above description uniquely defines a DFS-traversal and its corresponding DFS-tree. Let c_0,⋯,c_l−1 be the subsequence of the DFS-order consisting of all joints which has degree 1 in the DFS-tree. Then the cycle graph grown during the second phase is defined by the l edges (c_0,c_1),⋯,(c_l−1,c_0).
In addition, K is the number of branches grown on the third phase, i-th of which connects the joints x_i and y_i for all integers 0≤i<K.
The input satisfies the following constraints:
The output should be in the following format:
W L
s_0 s_1 ⋯ s_L−1
where W is the maximum sum of tastiness of a set s={s_0,⋯,s_L−1} of fruits LaLa can harvest from the crop without harming any branches.
The output should satisfy the following constraints:
The following illustrates the crop described in the sample test.
Note that there can be multiple branches directly connecting the same pair of joints.
