Set 106Question 28

Mahi's Mixed-Cost Reachability Planner

ExtremeWritten in CMust finish in 5 seconds

Mahi is modeling a network at a research lab where most hops cost 1 but special "fast lanes" cost 0, and needs minimum-cost reachability between many node pairs.

What your program reads

Line1: N M. Line2: N integers (jump distances). Line3: Q. Next Q lines: start end.

What your program prints

Minimum cost per query, or -1.

Limits

1 ≤ N ≤ 10^5

Example input

5 2
2 3 1 1 1
1
1 5

Expected output

1
main.c

Your work is saved in this browser as you type.

Loading editor…
Input for Run

Run tries your code on the input above and shows what it prints. Submit checks your output against every test, including hidden ones.

Shortcut: Ctrl + Enter sends it to the judge.

Mahi's Mixed-Cost Reachability Planner · DIU ContestHub