luogu#P3451. [POI 2007] ATR-Tourist Attractions

    ID: 2525 远端评测题 3000ms 64MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2007POI(波兰)O2优化最短路状压 DP

[POI 2007] ATR-Tourist Attractions

Background

English Edition

Problem Description

You are given an undirected graph with nn vertices and mm edges, where each edge has a weight.

You need to find a shortest path from 11 to nn that, while satisfying the given gg constraints, can stop at every vertex numbered from 22 to k+1k+1.

Each constraint is of the form ri,sir_i, s_i, meaning that you must have stopped at rir_i before stopping at sis_i.

Note that “stop” here does not mean merely passing through.

Input Format

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

Each of the next mm lines contains three integers pi,qi,lip_i, q_i, l_i, meaning there is an edge of weight lil_i between pip_i and qiq_i.

The next line contains an integer gg.

Each of the next gg lines contains two integers ri,sir_i, s_i, representing one constraint.

Output Format

Output a single integer on one line — the length of the shortest path.

8 15 4
1 2 3
1 3 4
1 4 4
1 6 2
1 7 3
2 3 6
2 4 2
2 5 2
3 4 3
3 6 3
3 8 6
4 5 2
4 8 6
5 7 4
5 8 6
3
2 3
3 4
3 5
19

Hint

Constraints:

  • For 100%100\% of the testdata, the following hold:
  • 2n2×1042 \le n \le 2 \times 10^4.
  • 1m2×1051 \le m \le 2 \times 10^5.
  • 0kmin(20,n2)0 \le k \le \min(20, n-2).
  • 1pi<qin1 \le p_i < q_i \le n.
  • 1li1031 \le l_i \le 10^3.
  • ri,si[2,k+1], risir_i, s_i \in [2, k+1],\ r_i \ne s_i.
  • There are no multiple edges, and a solution always exists.

Translated by ChatGPT 5