시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
4 초 | 1024 MB | 4 | 2 | 2 | 100.000% |
Every other winter, $\color{blue}{\text{LaLa}}$ helps her aunt, $\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_u$ grows on each joint $u$.
The cultivation of the crop can be divided into three phases.
$\color{blue}{\text{LaLa}}$'s goal is to maximize the sum of tastiness of the fruits she has harvested. However, $\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 $\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:
$N$ $M$
$T_0$ $T_1$ $\cdots$ $T_{N-1}$
$u_0$ $v_0$
$u_1$ $v_1$
$\vdots$
$u_{M-1}$ $v_{M-1}$
$K$
$x_0$ $y_0$
$x_1$ $y_1$
$\vdots$
$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 \le 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, \cdots, 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), \cdots, (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 \le i < K$.
The input satisfies the following constraints:
The output should be in the following format:
$W$ $L$
$s_0$ $s_1$ $\cdots$ $s_{L-1}$
where $W$ is the maximum sum of tastiness of a set $s = \lbrace s_0, \cdots, s_{L-1} \rbrace$ of fruits $\color{blue}{\text{LaLa}}$ can harvest from the crop without harming any branches.
The output should satisfy the following constraints:
6 7 1 1 1 1 1 1 0 1 1 2 2 3 2 4 1 5 1 4 0 5 1 2 5
2 2 0 4
The following illustrates the crop described in the sample test.
Note that there can be multiple branches directly connecting the same pair of joints.
Camp > Osijek Competitive Programming Camp > Winter 2023 > Day 9: Magical Story of LaLa H번