#P9813. [CCC 2015 S4] Convex Hull

[CCC 2015 S4] Convex Hull

Problem Description

Given an undirected graph with nn points and mm edges, each edge has two weights tit_{i} and hih_{i}.

You need to find a path from ss to tt such that the sum of hih_{i} on the path is <k< k, and the sum of tit_{i} is as small as possible. You only need to output this minimum value. If no path satisfying the condition can be found, output 1-1.

Input Format

The first line contains three integers k,n,mk, n, m.

The next mm lines each contain four integers ui,vi,ti,hiu_{i}, v_{i}, t_{i}, h_{i}, representing an edge between uiu_{i} and viv_{i}, with edge weights {ti,hi}\{t_{i}, h_{i}\}.

The last line contains two integers s,ts, t.

Output Format

If there exists a path satisfying the condition, output one line with one integer, the minimum possible sum of tit_{i}.

Otherwise, output one line with 1-1.

10 4 7
1 2 4 4
1 3 7 2
3 1 8 1
3 2 2 2
4 2 1 6
3 4 1 1
1 4 6 12
1 4
7
3 3 3
1 2 5 1
3 2 8 2
1 3 1 3
1 3
-1

Hint

Constraints:

For 20%20\% of the testdata, k=1k = 1, 2n2002 \leq n \leq 200.

For another 20%20\% of the testdata, k=1k = 1, 2n2×1032 \leq n \leq 2 \times 10^{3}.

For 100%100\% of the testdata, 0hi2000 \leq h_{i} \leq 200, 1ti1051 \leq t_{i} \leq 10^{5}, 1k2001 \leq k \leq 200, 2n2×1032 \leq n \leq 2 \times 10^{3}, 1m1041 \leq m \leq 10^{4}, and sts \neq t.

Translated by ChatGPT 5