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

문제

You are trying to organize a group of skiers. The skiers are taking a trip to a large mountain, which has been rented for the day.

There are N rest points numbered from 1 to N on the mountain, and they are connected by N-1 slopes. Each slope starts at some rest point and goes directly to another rest point, with no intermediate slopes or rest points. A slope can be traversed in only one direction.

Each skier starts at the summit rest point and traverses a slope to reach another rest point. From there, the skier can traverse another slope to reach another rest point, and so on. Once a skier reaches their destination rest point, they stop skiing for the day and head to the ski lodge for hot cocoa. The destination rest point cannot be the summit rest point. However, notice that a skier's destination rest point can be the start of zero or more slopes; that is, a skier does not necessarily have to keep using available slopes until there are none available: they can always walk carefully down the rest of the mountain! For all rest points, there is exactly one sequence of slopes that a skier can use to reach it from the summit rest point.

Each slope can accommodate only a certain total number of skiers in a day, after which the snow gets too choppy to ski. In addition, the ski resort can charge or reward each skier for each slope that they ski on. Each slope may have a different price, and each skier must pay the price for each slope they ski on. A slope's price can be positive, zero, or even negative; a negative price represents a bounty awarded for testing that slope. As the organizer, you pay all the slope prices and collect all the bounties on behalf of your group of skiers. Notice that if multiple skiers use the same slope, you pay that slope's price or collect the slope's bounty multiple times. The sum of all costs you pay minus the sum of all bounties you collect is the total expense for the trip. The expense can be positive, zero, or negative. A negative expense means that you actually made money on the trip!

As the organizer, you want to figure out the maximum number of skiers that you can put on the mountain. Also, you would like to figure out the minimum possible expense for a trip with that maximum number of skiers.

입력

The first line of the input gives the number of test cases, T. T test cases follow. The first line of a test case contains a single integer N: the number of rest points on the mountain.

Each of the final N-1 lines of a test case describes a slope via four integers Ui, Vi, Si, and Ci. These are the slope's starting rest point, the slope's ending rest point, the maximum number of skiers the slope can accommodate, and the slope's price per skier, respectively.

The summit rest point where the skiers start from is always numbered 1.

출력

For each test case, output one line containing Case #x: y z, where x is the test case number (starting from 1), y is the maximum number of skiers, and z is the minimum expense for having y skiers ski at least one slope each.

제한

  • 1 ≤ UiN, for all i.
  • 2 ≤ ViN, for all i. (No slope can end at the summit rest point.)
  • UiVi, for all i.
  • 1 ≤ Si ≤ 105, for all i.
  • -105Ci ≤ 105, for all i.
  • There is exactly one sequence of slopes that a skier can use to reach rest point r from the summit rest point, for all r.

Test Set 1 (10점)

  • 1 ≤ T ≤ 100.
  • 2 ≤ N ≤ 1000.

Test Set 2 (22점)

  • T = 17.
  • 2 ≤ N ≤ 105.

예제 입력 1

2
4
1 2 2 5
1 3 2 5
3 4 1 -2
7
4 7 2 2
1 3 5 5
1 4 2 -1
3 2 3 -2
3 5 2 -1
3 6 2 2

예제 출력 1

Case #1: 4 18
Case #2: 7 15

힌트

In Sample Case #1, we can send one skier to rest point 4, one skier to rest point 3, and two skiers to rest point 2.

In Sample Case #2, we can send three skiers to rest point 2, two skiers to rest point 5, and two skiers to rest point 4.

Notice that the first slope listed in a test case does not need to start at the summit rest point, and that slopes can have Ui > Vi.

채점 및 기타 정보

  • 예제는 채점하지 않는다.