#P15803. [GESP202603 七级] 物流网络

    ID: 17866 远端评测题 1000ms 512MiB 尝试: 4 已通过: 1 显示难度普及+/提高− 上传者: 标签>图论最短路2026GESP

[GESP202603 七级] 物流网络

Background

Related multiple-choice and true/false questions: https://ti.luogu.com.cn/problemset/1211.

Problem Description

A logistics network consists of nn cities and mm bidirectional roads. Each road has two attributes:

  • Transport cost wiw_i.
  • Scenic rating bib_i.

When a truck transports goods from city 11 to city nn, it needs to pay the sum of the transport costs of the roads it travels on.

To promote tourist routes, the logistics company offers a discount policy: along the transport path, the transport cost of the road with the highest scenic rating can be waived. If there are multiple roads whose scenic rating ties for the maximum, only the cost of one of them is waived.

Please compute the minimum transport cost from city 11 to city nn.

Input Format

The first line contains two integers n,mn, m, representing the number of cities and the number of roads.

The next mm lines each contain four integers u,v,w,bu, v, w, b, indicating a bidirectional road connecting city uu and city vv, where ww is the transport cost and bb is the scenic rating.

Output Format

Output one integer, representing the minimum cost from city 11 to city nn.

If city nn cannot be reached, output -1.

3 3
1 2 10 5
2 3 20 6
1 3 100 1
0

Hint

Sample Explanation

Path 1→2→31\to 2\to 3: cost 10+2010+20, maximum scenic rating 66 (edge 2−32-3). Waive 2020, total cost 1010.

Path 1→31\to 3: cost 100100, maximum scenic rating 11 (edge 1−31-3). Waive 100100, total cost 00.

Constraints

1≤n≤50001\leq n\leq 5000, 1≤m≤50001\leq m\leq 5000, 1≤w,b≤1091\leq w,b\leq 10^9.

Translated by ChatGPT 5