아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Protect the Pollen!

시간 제한5초메모리 제한1024 MB

요약
트리에서 보내는 정점 집합의 꿀벌 수 합이 S 이하이고 모든 간선의 두 끝점 중 하나는 남아 있어야 할 때, 보내는 집합의 총 꽃가루 생산력을 최대로 구한다.
난이도

보통10점 중 7점

유형
트리, 동적 계획법, DFS
정답자
아직 제출이 없습니다

문제

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 s_ks\_k bees and has a pollination power of p_kp\_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 (1≤N≤3001 \leq N \leq 300), which is the number of flowers, and SS (1≤S≤3001 \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 s_ks\_k (1≤s_k≤3001 \leq s\_k \leq 300), which is the number of bees in this family, and p_kp\_k (1≤p_k≤1001 \leq p\_k \leq 100), which is the pollination power of this family.

The last N−1N-1 lines describe the vines.  Each of these lines contains two distinct integers uu (1≤u≤N1 \leq u \leq N) and vv (1≤v≤N1 \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.

예제2

  1. 예제 1

    입력
    5 10
    2 1
    2 2
    2 4
    2 8
    2 16
    1 2
    2 3
    3 4
    4 5
    
    예상 출력
    21
    
  2. 예제 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