#P8626. [蓝桥杯 2015 省 A] 灾后重建

    ID: 7621 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2015生成树蓝桥杯省赛根号分治

[蓝桥杯 2015 省 A] 灾后重建

Description

Pear City has a total of NN (50000\le 50000) settlements, and there are MM (2×105\le 2\times 10^5) undirected roads connecting these settlements. Any two settlements can reach each other through these undirected roads. This situation lasted until recently, when a severe earthquake destroyed all MM roads.

After the earthquake, Pear plans to repair some of the roads. Repairing the ii-th road takes PiP_i time. However, Pear does not plan to make all nodes connected; instead, he chooses some specially indexed nodes and makes them connected.

Pear has QQ (50000\le 50000) queries. In each query, he selects all nodes whose indices are in [l,r][l,r] and whose index satisfies modK=C\bmod{K}=C, and repairs some roads to make these nodes connected. Since all road repairs can start at the same time, the completion time depends on the road that takes the longest time, that is, the maximum PiP_i among the roads involved.

Can you help Pear compute the minimum time needed for each query? The queries are independent, meaning the repair plan in one query is not actually carried out.

Input Format

The first line contains three positive integers NN, MM, and QQ, as described above.

The next MM lines each contain three positive integers XiX_i, YiY_i, and PiP_i, representing an undirected road between XiX_i and YiY_i that takes PiP_i time to repair. Self-loops and multiple edges may exist. 1Pi1061 \le P_i \le 10^6.

The next QQ lines each contain four positive integers LiL_i, RiR_i, KiK_i, and CiC_i, indicating that the nodes in this query are all nodes in the interval [Li,Ri][L_i,R_i] whose indices satisfy modKi=Ci\bmod{K_i}=C_i. It is guaranteed that at least two nodes participate in each query.

Output Format

Output QQ lines. Each line contains one positive integer, the answer to the corresponding query.

7 10 4
1 3 10
2 6 9
4 1 5
3 7 4
3 6 9
1 5 8
2 7 4
3 2 10
1 7 6
7 6 9
1 7 1 0
1 7 3 1
2 5 1 0
3 7 2 1
9
6
8
8

Hint

For 20%20\% of the testdata, N,M,Q30N,M,Q \le 30.

For 40%40\% of the testdata, N,M,Q2000N,M,Q \le 2000.

For 100%100\% of the testdata, N50000N \le 50000, M2×105M \le 2 \times 10^5, Q50000Q \le 50000, Pi106P_i \le 10^6. LiL_i, RiR_i, and KiK_i are all in the range [1,N][1,N], and CiC_i is in the range [0,Ki)[0,K_i).

Time limit: 5 seconds, 256 MB.

Lanqiao Cup 2015 Provincial Contest A Division, Problem J.

Translated by ChatGPT 5