Shortest path in acyclic graph with a low degree

For a weighted directed acyclic graph on vertices nsuch that each vertex has no more 5and does not exceed 5. Nodes are 0, 1, ..., n - 1oriented this way

0 1 2 3 4

5 6 7 8 9

10 11 12 13 14

...

n-5 n-4 n-3 n-2 n-1

Edges can only be from a node in a line to a certain node in the next line.

We will be given requests qby setting the shortest path length from uto v. Here it ncan be before 10^5and qbefore 10^4. Weights are positive integers.

Can we work better than O(nq)dynamic programming (which obviously doesn't work here)?

+4
1

, , , ... O(n) (EDIT: O(n^(4/3))) O (1).

, , O(n^2). ( , , , )

k, n/(5*k). ( , )

(, , ) : O((n/k)^2).

, , , . O(k). O(k^2).

: O((n/k)^2 + k^2). k=sqrt(n), O(n).

O(1): 5 u, 5 v- ( ), 25 u- > v

, . k , , O(k*(n/k)^2). O(n^2/k + k^2), k k=n^(2/3), O(n^(4/3)) O(q)

+2

Source: https://habr.com/ru/post/1675783/


All Articles