electicode
АсосӣКурсҳоМанбаъҳоМасъалаҳо
Ҳамаи масъалаҳо
Khimio
Khayyam Finals 2025

Electi Robot - KhIMIO

2 сМаҳдудияти вақт
256 МБМаҳдудияти ҳофиза
Ҳамаи ҳалҳо

Тавсифи масъала

You are given a connected undirected graph with NNN vertices and MMM edges. Each edge eee has a nonnegative weight wew_ewe​ indicating the energy required to traverse it. There are QQQ robots. Robot ii has a battery with (to-be-determined) capacity , starts at vertex , and wants to reach vertex .

Ҳал кардан мехоҳӣ?

Ворид шав, кодро ҳамин ҷо навис ва натиҷаро дарҳол бин.

Ворид шудан

electicode© 2026. Ҳамаи ҳуқуқҳо ҳифз шудаанд.

Намуд
i
bib_ibi​
UiU_iUi​
ViV_iVi​

Some vertices are equipped with battery chargers. A robot that is currently at a charger vertex may instantly recharge its battery back to full capacity (i.e., to bib_ibi​). It is guaranteed that both UiU_iUi​ and ViV_iVi​ are charger vertices for every robot iii.

A robot moves along edges one by one. Traversing an edge eee consumes wew_ewe​ units of its current battery. A robot may only traverse an edge if its current battery level is at least wew_ewe​ at that moment. Robots may visit vertices and edges multiple times and may recharge any number of times at charger vertices. Robots act independently (no interference or congestion).

For each robot iii (1≤i≤Q)(1 \le i \le Q)(1≤i≤Q), determine the minimum battery capacity bi⋆b_i^\starbi⋆​ such that robot iii can start at UiU_iUi​ with a full battery, follow some route that respects the energy and recharge rules, and arrive at ViV_iVi​.

Input Format

  • The first line contains one integer T (1≤T≤103)T \ (1 \leq T \leq 10^3)T (1≤T≤103), the number of tests.
    • Then, for each test:

      • The first line contains three separated integers N,M,Q (1≤N,M,Q≤2⋅105)N, M, Q \ (1 \leq N, M, Q \leq 2 \cdot 10^5)N,M,Q (1≤N,M,Q≤2⋅105).
      • The second line contains NNN integers c1,c2,…,vNc_1, c_2, \ldots, v_Nc1​,c2​,…,vN​. If , then there is battery charger at vertex . Otherwise .
      • Then, MMM lines follow, the description of the graph. Each line consists of three separated integers xi, yi, wix_i, \ y_i, \ w_ixi​, yi​, wi​ (, ), description of edge . There is edge between vertex and in the graph with length . The graph might contain multiple edges.
      • Then, QQQ lines follow, description of the queries. Each line consists of two separated integers Ui,ViU_i, V_iUi​,Vi​ (1≤Ui,Vi≤N1 \leq U_i, V_i \leq N1≤U.

It is guaranteed, that the graph is connected.

Constraints

  • The total sum of NNN in all tests doesn't exceed 2⋅1052 \cdot 10^52⋅105
  • The total sum of MMM in all tests doesn't exceed 2⋅1052 \cdot 10^52⋅105
  • The total sum of QQQ in all tests doesn't exceed 2⋅1052 \cdot 10^52⋅105

Output Format

For each test, and for each query print the minimum capacity battery required.

Scoring

Let SNS_NSN​ be the sum of NNN in all tests.
With the same logic, let SM,SQS_M, S_QSM​,SQ​ be the sums of MMM and QQQ respectively.

SubtasksAdditional restrictionsPointsRequired Subtasks
0Sample0-
1SN,SM,SQ≤200S_N, S_M, S_Q \leq 200SN​,SM​,SQ​≤20090
2SN,SM,SQ≤2⋅103S_N, S_M, S_Q \leq 2 \cdot 10^3SN​,SM​,SQ​≤2⋅
3M=N−1, xi=i, yi=i+1M = N - 1, \ x_i = i, \ y_i = i + 1M=N−1, xi​=i, yi​
4M=N−1, Ui=1M = N - 1, \ U_i = 1M=N−1, Ui​=120-
5-390, 1, 2, 3, 4

Мисолҳо

Мисол 1
Вуруд
1 7 9 3 1 0 1 0 0 0 1 1 2 3 1 4 2 2 3 3 2 5 5 4 5 9 5 7 2 7 3 4 3 6 3 7 6 2 1 3 1 7 3 7
Баромад
6 6 4
ci=1c_i=1
ci​=1
iii
ci=0c_i=0ci​=0
1≤xi,yi≤N1 \leq x_i, y_i \leq N
1≤xi​,yi​≤N
1≤wi≤1091 \leq w_i \leq 10^91≤wi​≤109
iii
xix_ixi​
yiy_iyi​
wiw_iwi​
i​
,
Vi​
≤
N
103
16
0, 1
=
i+
1
16
-