#P9289. [ROI 2018] Quantum teleportation

[ROI 2018] Quantum teleportation

Background

Translated from ROI 2018 Day1 T4. Квантовая телепортация (Quantum teleportation)。

Problem Description

On a 2D Cartesian coordinate plane, there are kk CPUs numbered 1k1 \dots k.

The position of each CPU can be represented by coordinates on the plane. CPU 11 is located at (1,1)(1,1), and CPU kk is located at (n,m)(n,m). It is guaranteed that all CPUs are on integer grid points, and for each CPU with coordinates (xi,yi)(x_i, y_i), it holds that 1xin1 \le x_i \le n and 1yim1 \le y_i \le m.

The time for CPU ii to transmit a piece of data to CPU jj via the bus is 2max(xixj,yiyj){2^{\max(|x_{{i}}-x_{{j}}|,|y_{{i}}-y_{{j}}|)}} time units.

Find the minimum time needed to send the data from CPU 11 to CPU kk, and output one valid plan.

Input Format

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

The next kk lines each contain two integers xi,yix_i,y_i.

Output Format

The first line contains an integer LL, which denotes how many CPUs are visited in the fastest plan.

The second line contains LL integers, denoting the CPUs visited in order.

If there are multiple paths with the minimum time, output any one of them.

4 5 3
1 1
2 3
4 5
3
1 2 3
5 6 9
1 1
4 3
4 6
2 5
3 1
3 3
3 6
5 4
5 6
5
1 6 2 8 9 

Hint

For all testdata, 2n,m,k100002 \leq n,m,k \leq 10000.

Constraints

Subtask ID n,m,kn,m,k Special Property
11 2n,m,k202 \leq n,m,k \leq 20 None
22 2n,m,k5002 \leq n,m,k \leq 500
33 2n,m,k100002 \leq n,m,k \leq 10000 There is only one CPU in each row and each column
44 None

Translated by ChatGPT 5