Given the source of the node, dest node, and intermediate nodes, how do you determine if the shortest Manhattan distance is blocked?

Here is the full name that I would post, but it takes too long:

Given the source of the node, dest node, and intermediate nodes, how do you determine if Manhattan's shortest distance is blocked by intermediate nodes?

an image of the problem

I drew a chart to make it clearer. On the left side, ā€œuā€ is the source of the node, and ā€œvā€ is the destination of the node. The nodes labeled 1 through 6 are intermediate nodes. The shortest Manhattan distance from u → v will be 12, and the intermediate nodes form a wall blocking it. The diagram on the right, where u 'is the source and v' is the destination, shows that the intermediate nodes 1 through 5 do not block the shortest Manhattan distance from u 'to v'.

I am trying to find an algorithm that does not require me to actually perform a graph search (e.g. BFS), because the distance between u and v could potentially be very large.

+5
source share
2 answers

, , - , ( , ), , , node , . , , .

. O (n) , , , . , , , , - . , , , . , , - .

, , O (n), n - , , , .

, , . -, , 3x3. , , , . , , , node, . , , node node , - node node.

O (n), n - , O (n) , node 12 - 8 . , node , node, , . , , .

, , , , , , . , , . , , . DFS , , , , - SCC. O (n).

, O (n 2), , .

, !

+2

:

, , - . ( , x/y, , node)

. , , , , . A node B , :

  • B node
  • , B B, ( )

, , .

- O (m * n), m, n - . , , templatetypedef .

: , ,

0

All Articles