#P6436. 「EZEC-1」越狱

    ID: 5248 远端评测题 1000~3000ms 125~500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>搜索图论二分最短路Tarjan最近公共祖先,LCA

「EZEC-1」越狱

Description

Little E's escape route can be viewed as occurring on nn islands. These islands are connected pairwise by n1n-1 sea routes, forming a tree.

Each island has enough supplies. Assume that for every day he sails at sea, he must spend 11 unit of food. A greedy shop owner states that a backpack that can hold kk units of food will be sold for kk ten-thousand yuan.

PF may order the construction of a bidirectional sea route between any two islands uu and vv that satisfy both conditions: the travel time between them is not greater than dd, and on the route from island vv to island uu there are at least qq islands ( excluding uu and vv ). The travel time of this new route is time(uv)2\left\lfloor \dfrac{time(u \to v)}{2}\right\rfloor. Due to budget issues, he can build only one extra route.

Little E can use the official routes ( including the newly added route ) to determine PF's shortest time to each island.

PF will discover Little E's escape at time tt and then start the pursuit.

To save money while escaping PF's chase, Little E wants you to write a program to compute the minimum kk such that he can successfully escape to at least ll islands.

Supplying does not take time. Getting caught on the way still counts as getting caught. Arriving at the same time does not count as being caught.

Replenishing supplies on an island takes no time and can be done infinitely many times, as long as the backpack has enough capacity.

Problem summary:

There are two people aa and bb and a tree with nn nodes. aa starts tt seconds earlier than bb. If the travel time between two nodes is not greater than dd, then bb can build a route between these two nodes with travel time time(uv)2\left\lfloor \dfrac{time(u \to v)}{2}\right\rfloor. Find a plan such that aa's shortest time to at least ll nodes is not longer than bb's, and on this basis, make the maximum distance between islands as small as possible.

Input Format

The first line contains five integers n,t,d,l,qn,t,d,l,q, representing the number of islands, the time when PF discovers the escape, the travel-time limit required to build a route, the minimum number of islands that must be reachable, and the required number of intermediate islands for building a route. Both of their starting points are node 11.

The next n1n-1 lines each contain four integers u,v,pi,eiu,v,p_i,e_i, indicating that there is a route between islands uu and vv. pip_i is the time for Little E to travel along this route, and eie_i is the time for PF to travel along this route. Routes are bidirectional.

Output Format

If there is a solution, output two lines.

The first line contains an integer kk, indicating the minimum amount of money needed to escape (unit: ten-thousand yuan).

The second line contains an integer rr, indicating the number of islands that can be reached when buying a backpack costing kk (node 11 also counts).

If there is no solution, output only no solution.

5 3 20 4 2
1 2 5 5
2 3 5 5
2 4 7 10
1 5 4 1
7
4
5 2 6 3 2
1 2 5 3
2 3 8 6
1 4 8 2
2 5 4 6
5
3
5 0 23 4 1
1 2 21 26
1 3 14 16
3 4 4 5
1 5 19 18
no solution

Hint

[Sample Explanation]

Sample 11:

For sample 11, the final reachable nodes are 1,2,4,51,2,4,5, and the minimum cost is 77. Since warden PF goes from node 353 \to 5 along the path 51235 \to 1 \to 2 \to 3, the number of intermediate nodes is q\ge q, so warden PF can add an edge between nodes 33 and 55. If warden PF chooses to add the edge 535 \to 3, then the time to reach node 33 is $3 + 1 + \left\lfloor \dfrac{1+5+5}{2}\right\rfloor = 9$. However, Little E's shortest time to node 33 is 5+5=105 + 5 = 10, which does not satisfy the condition. Therefore, no matter how large kk is, node 33 is unreachable.


[Constraints]

Test Point ID nn\le tt\le pi,eip_i,e_i\le dd\le Time Limit Memory Limit Feature
11 1010 5050 1s1s 128M128M Adding an edge does not affect the answer
22 1616 None
3,43,4 500500 500{500} 500500 Adding an edge does not affect the answer
55 500{500} q=0q = 0
6,76,7 None
88 2.5×103\small{2.5 \times 10^3} 10810^8 Adding an edge does not affect the answer
9,109,10 q=0q = 0
111411 \sim 14 None
1515 256M256M
1616 7.5×103\small{7.5 \times 10^3} 2s2s
1717 1s1s
182018 \sim 20 3s3s 512M512M

For 100%100\% of the data, n7.5×103n\le 7.5\times 10^3, 1ln1\le l\le n, 0t1080\le t \le 10^8, 0ui<vin0 \le u_i<v_i \le n, 1pi,ei,d1081\le p_i,e_i,d\le 10^8, 0q200\le q\le 20.

It is guaranteed that the number of possible plans for the newly built bidirectional route does not exceed 5×1065 \times 10^6.

Translated by ChatGPT 5