PivotOJ

Protect the Pollen!

시간 제한: 5000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2021BOJ 24756

문제

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 kk consists of sks_k bees and has a pollination power of pkp_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 SS 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 NN (1N3001 \leq N \leq 300), which is the number of flowers, and SS (1S3001 \leq S \leq 300), which is the maximum number of bees you can send on the mission. The flowers are numbered 11 to NN.

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

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

출력

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
출력
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
출력
33
코드를 제출하려면 로그인하세요.