LaLa and Harvesting

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

Every other winter, LaLa\color{blue}{\text{LaLa}} helps her aunt, Aisha\color{red}{\text{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_uT\_u grows on each joint uu.

The cultivation of the crop can be divided into three phases.

  1. At the start of the first phase, a seed is planted on an open field. The seed eventually grows to form a cactus graph, a simple connected graph where every edge belongs to at most one cycle. This is the only phase where new joints grow.
  2. Consider the DFS-tree of the cactus grown during the first phase. At the start of the second phase, Aisha\color{red}{\text{Aisha}} encloses the crop with a ring-shaped framework by attaching the leaves (vertices of degree 1, where only the edges in the DFS-tree are counted for degree, which possibly includes the root of the DFS-tree) to the ring. This forces the crop to grow additional branches joining adjacent joints on the framework, forming a cycle graph, and to start producing the fruits. Please read the input specification for detailed description.
  3. At the start of the third phase, Aisha\color{red}{\text{Aisha}} connects to the framework a magic\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}} tool that feeds the crop with the constant flow of extra nutrition. As a result, some new branches grow. The union of the branches grown during this phase form a very dense tree: every non-leaf vertex of the tree has degree 12\ge 12. The harvesting begins at the end of this phase.

LaLa\color{blue}{\text{LaLa}}'s goal is to maximize the sum of tastiness of the fruits she has harvested. However, LaLa\color{blue}{\text{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\color{blue}{\text{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:

NN MM

T_0T\_0 T_1T\_1 \cdots T_N1T\_{N-1}

u_0u\_0 v_0v\_0

u_1u\_1 v_1v\_1

\vdots

u_M1u\_{M-1} v_M1v\_{M-1}

KK

x_0x\_0 y_0y\_0

x_1x\_1 y_1y\_1

\vdots

x_K1x\_{K-1} y_K1y\_{K-1}

where NN is the number of joints, numbered from 00 to N1N-1, MM the number of branches grown during the first phase, and the ii-th branch connects the joints u_iu\_i and v_iv\_i for all integers 0i<M0 \le i < M.

Consider the DFS-tree built over the cactus graph grown during the first phase where the DFS traversal starts at joint 00 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_l1c\_0, \cdots, c\_{l-1} be the subsequence of the DFS-order consisting of all joints which has degree 11 in the DFS-tree. Then the cycle graph grown during the second phase is defined by the ll edges (c_0,c_1),,(c_l1,c_0)(c\_0, c\_1), \cdots, (c\_{l-1}, c\_0).

In addition, KK is the number of branches grown on the third phase, ii-th of which connects the joints x_ix\_i and y_iy\_i for all integers 0i<K0 \le i < K.

The input satisfies the following constraints:

  • All the numbers in the input are integers.
  • 2N5002 \le N \le 500, N1M2NN-1 \le M \le 2N, 1Kmin(N1,100)1 \le K \le \min(N-1, 100)
  • 1T_u200,0001 \le T\_u \le 200\\,000 for all integers 0u<N0 \le u < N
  • 0u_i<v_i<N0 \le u\_i < v\_i < N for all integers 0i<M0 \le i < M
  • u_iu_ju\_i \ne u\_j or v_iv_jv\_i \ne v\_j for all integers 0i<j<M0 \le i < j < M
  • 0x_i<y_i<N0 \le x\_i < y\_i < N for all integers 0i<K0 \le i < K
  • x_ix_jx\_i \ne x\_j or y_iy_jy\_i \ne y\_j for all integers 0i<j<K0 \le i < j < K
  • The union of edges (u_i,v_i)(u\_i, v\_i) forms a cactus over the vertices {0,1,,N1}\lbrace {0, 1, \cdots, N-1} \rbrace.
  • The union of edges (x_i,y_i)(x\_i, y\_i) forms a tree over the set of vertices {x_0,y_0,x_1,y_1,,x_K1,y_K1}\lbrace x\_0, y\_0, x\_1, y\_1, \cdots, x\_{K-1}, y\_{K-1} \rbrace where each vertex with degree greater than 11 has degree at least 1212.

출력

The output should be in the following format:

WW LL

s_0s\_0 s_1s\_1 \cdots s_L1s\_{L-1}

where WW is the maximum sum of tastiness of a set s={s_0,,s_L1}s = \lbrace s\_0, \cdots, s\_{L-1} \rbrace of fruits LaLa\color{blue}{\text{LaLa}} can harvest from the crop without harming any branches.

The output should satisfy the following constraints:

  • All the numbers in the output are integers.
  • 0LN0 \le L \le N
  • 0s_0<s_1<<s_L1<N0 \le s\_0 < s\_1 < \cdots < s\_{L-1} < N
  • There are no edges directly connecting the vertices s_is\_i and s_js\_j for all integers 0i<j<L0 \le i < j < L.
  • _i=0L1T_s_i=W\sum\_{i=0}^{L-1}T\_{s\_i} = W

힌트

The following illustrates the crop described in the sample test.

  • The regular black edges denote the branches grown during the first phase that is part of the DFS-tree.
  • The dotted black edges denote the branches grown during the first phase that is NOT part of the DFS-tree.
  • The red edges denote the branches grown during the second phase.
  • The blue edges denote the branches grown during the third phase.

Note that there can be multiple branches directly connecting the same pair of joints.