#P7591. 狩猎(2021 CoE-II D)

    ID: 8270 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2021Special JudgeO2优化期望

狩猎(2021 CoE-II D)

Problem Description

In the territory of the lioness Dina\text{Dina}, there are nn fixed hunting spots. At hunting spot ii, the probability of catching prey is pip_i. There are several directly connected bidirectional roads among Dina’s den (nest) and the nn hunting spots.

Every morning, Dina\text{Dina} starts from her den and randomly chooses a hunting spot uu that is adjacent to the den to hunt once. If she does not catch prey, she will randomly choose another hunting spot vv that is adjacent to the current hunting spot uu and hunt once again. If she still does not catch prey at hunting spot vv, she will continue hunting following the same process. If she catches prey at some hunting spot, she will immediately return to the den and end the hunt. If the current hunting spot uu is adjacent to the den but is not adjacent to any other hunting spot, Dina\text{Dina} will also choose to return to the den immediately, and then randomly choose one hunting spot adjacent to the den to continue the hunting process described above. At each hunting spot, Dina\text{Dina} hunts exactly once and then leaves, but she may return to the same spot later to hunt again. In this problem, if there is a directly connected bidirectional road between location uu and location vv, then uu and vv are called adjacent; otherwise they are called non-adjacent.

Let the den be numbered 00, and the nn hunting spots be numbered from 11 to nn. Moving from location uu to location vv costs hu,vh_{u,v} stamina and tu,vt_{u,v} time. Each time Dina\text{Dina} hunts at hunting spot ii, she consumes hih_i stamina and tit_i time. Each time Dina\text{Dina} arrives at a hunting spot and finishes one hunt there, she evaluates her stamina consumption and time spent. If her stamina consumption has reached (or exceeded) the limit HH, she immediately returns to the den and ends the hunt. If her time spent has reached (or exceeded) the limit TT, she also immediately returns to the den and ends the hunt. Dina\text{Dina} only evaluates after arriving at a hunting spot and completing one hunt; she does not evaluate at any other moment. If she is currently at the den, she evaluates as soon as she arrives at the den, because there is no prey to catch at the den.

Note that Dina\text{Dina} does not evaluate while moving along a road between two locations. Therefore, it is possible that when she arrives at a hunting spot but has not hunted yet, her stamina consumption or time spent has already exceeded the limit. In this case, Dina\text{Dina} will still perform one hunt, and only then evaluate.

When Dina\text{Dina} returns to the den because she successfully catches prey, or because her stamina consumption or time spent reaches (or exceeds) the corresponding limit, or because the current hunting spot is non-adjacent to all other hunting spots, she always chooses a path with the minimum total time to return to the den. If there are multiple paths with the minimum total time, she chooses the one with the minimum total stamina consumption. During the return to the den, Dina\text{Dina} does not hunt.

The whole process starting from leaving the den, and then returning to the den and ending the hunt due to one of the following three conditions:

  • successful hunting,
  • stamina consumption reaching (or exceeding) the limit HH,
  • time spent reaching (or exceeding) the limit TT,

is called one hunting. Given the roads between the den and hunting spots, the stamina and time cost of each road, the probability of catching prey at each hunting spot, and the stamina and time cost of hunting once at each hunting spot, determine the expected (average) stamina consumption and time spent for Dina\text{Dina} to complete one hunting.

Input Format

The first line contains an integer nn, denoting the number of hunting spots.

The next nn lines each contain three values: an integer hih_i, an integer tit_i, and a real number pip_i, denoting the stamina consumed, the time spent, and the probability of catching prey for one hunt at hunting spot ii, respectively.

Next is an integer mm, denoting the number of bidirectional roads connecting the locations. The following mm lines each contain four integers uu, vv, hu,vh_{u,v}, tu,vt_{u,v}, indicating that there is a directly connected road between location uu (0in0 \le i \le n) and location vv (0in0 \le i \le n, uvu \ne v), which costs hu,vh_{u,v} stamina and tu,vt_{u,v} time. Since the road is bidirectional, the stamina and time costs are the same in both directions.

The last line contains two integers HH and TT, denoting the limits of stamina and time, respectively.

Output Format

Output one line containing two real numbers, accurate to one digit after the decimal point, representing the expected stamina consumption and expected time spent for Dina\text{Dina} to complete one hunting. Your output is considered correct if the absolute error from the reference output is less than 10110^{-1}.

1
1 2 1.00
1
0 1 2 3
10 20
5.0 8.0
3
1 2 1.00
2 3 0.50
3 4 0.70
2
0 1 2 3
0 2 4 5
10 20
7.5 10.5

Hint

Subtasks are scored with bundled testdata.

Sample Explanation

Input #1

This input contains only one hunting spot. The road from the den to hunting spot 11 costs 22 stamina and 33 time. The stamina limit is 1010, and the time limit is 2020. One hunt at hunting spot 11 costs 11 stamina and 22 time. The probability of catching prey at hunting spot 11 is 1.001.00, meaning Dina will definitely catch prey. It is easy to see that the expected stamina consumption and time spent for one hunting are 5.0=(2+1+2)×100%5.0=(2+1+2) \times 100\% and 8.0=(3+2+3)×100%8.0=(3+2+3) \times 100\%, respectively.

Input #2

Compared with the first input, two more hunting spots are added, but only hunting spot 11 and hunting spot 22 are directly connected to the den by roads. There are no direct roads among the three hunting spots, but hunting spot 11 can be indirectly connected to hunting spot 22 through the den. The road from the den to hunting spot 22 costs 44 stamina and 55 time, and one hunt at hunting spot 22 costs 22 stamina and 33 time. The probability of catching prey at hunting spot 11 is 1.001.00, meaning Dina will definitely catch prey, so Dina\text{Dina} will immediately return to the den and end the hunt. The probability of catching prey at hunting spot 22 is 0.500.50, meaning there is a 50%50\% chance to catch prey, but since hunting spot 22 has no other hunting spot directly connected to it, regardless of whether Dina catches prey at hunting spot 22, she will choose to return to the den immediately. When returning to the den, she has already consumed 1010 stamina. According to the statement, regardless of whether Dina has caught prey, she will end the hunt. Since the initial choice is random, the probabilities of choosing hunting spot 11 and 22 from the den are both 50%50\%. By calculation, the expected stamina consumption and expected time spent for one hunting are 7.5=(2+1+2)×50%+(4+2+4)×50%7.5=(2+1+2) \times 50\%+(4+2+4) \times 50\% and 10.5=(3+2+3)×50%+(5+3+5)×50%10.5=(3+2+3) \times 50\%+(5+3+5) \times 50\%, respectively.


Constraints

  • Subtask 11: n=1n=1, 1010 points.
  • Subtask 22: 1n201 \le n \le 20, no hunting spot has a direct road to any other hunting spot, 2020 points.
  • Subtask 33: no special restrictions, 7070 points.

For 100%100\% of the testdata: 1n2001 \le n \le 200, 1hi101 \le h_i \le 10, 1ti101 \le t_i \le 10, 0pi10 \le p_i \le 1, 1mmin(n(n+1)/21 \le m \le \text{min}(n (n+1) / 220002000), 1hu,v201 \le h_{u,v} \le 20, 1tu,v201 \le t_{u,v} \le 20, 1H2001 \le H \le 200, 1T2001 \le T \le 200.


Conventions

  • Between locations uu and vv, there is at most one directly connected bidirectional road, and the same direct bidirectional road will not be given repeatedly.
  • Ignore the time needed for Dina\text{Dina} to perform evaluations.
  • In the input, the value representing the probability pip_i is a real number with two digits after the decimal point.

Translated by ChatGPT 5