시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB2819960.000%

문제

The Flariana flowers and the bumblebees form one of the nicest partnerships in the rainforest. In spring, several flowers bloom and start producing pollen. Special vines form a network of bridges between the flowers. Using the vines, there is exactly one way to get from each flower to any other flower.

Every flower has a family of bees on it. This family protects all of the vines that touch that flower. This means that every vine is protected by two families. The family on flower $k$ consists of $s_k$ bees and has a pollination power of $p_k$.

One day, a bee scout announced that there is a new flower patch over the hill and they need a group of bees to help pollinate it.

As the bee queen, you must select a set of families to send on the mission. For every vine, at least one of the two families currently protecting it must stay behind so the vine remains protected. All bees in the selected families must go. You are willing to send at most $S$ bees on the mission in total.

Determine the largest total pollination power that you can send on the mission.

입력

The first line contains the integer $N$ ($1 \leq N \leq 300$), which is the number of flowers, and $S$ ($1 \leq S \leq 300$), which is the maximum number of bees you can send on the mission. The flowers are numbered $1$ to $N$.

The next $N$ lines describe the families. Each of these lines contains two integers $s_k$ ($1 \leq s_k \leq 300$), which is the number of bees in this family, and $p_k$ ($1 \leq p_k \leq 100$), which is the pollination power of this family.

The last $N-1$ lines describe the vines.  Each of these lines contains two distinct integers $u$ ($1 \leq u \leq N$) and $v$ ($1 \leq v \leq N$), indicating that there is a vine between flowers $u$ and $v$.

출력

Display the largest total pollination power that you can send on the mission.

예제 입력 1

5 10
2 1
2 2
2 4
2 8
2 16
1 2
2 3
3 4
4 5

예제 출력 1

21

예제 입력 2

7 10
1 7
2 4
5 18
2 3
3 12
9 20
2 8
1 2
1 3
2 4
2 5
3 6
3 7

예제 출력 2

33

출처

ICPC > Regionals > North America > Rocky Mountain Regional > 2021 Rocky Mountain Regional Contest F번

  • 문제를 만든 사람: Howard Cheng