Suppose your group of nodes have nodes A-H. If you create a dummy node and link it to each node in P2 and do a query
path as shortest(from: uid(src_node), to: uid(dummy_node), numpaths: 8 ) {
link
}
It will return 4 paths (src - A - dummy_node; src - C - dummy_node; src - E - dummy_node; src - F - dummy_node).
And you can find out which nodes (from the group P2) it actually went to via _path_ key in the response.
An important point is to give numpath=size(P2) so that it continues to find all the paths, and you can retrieve all the nodes visited from the response.
If your P2 nodes are inter-connected then you can give an even higher number to numpaths to account for paths like src - A - B - dummy node. This is a hacky way to make it visit all nodes even if it has found the shortest path already. Your performance would suffer but you would be making only one query.
