Comments

How to solve A?

Oh I got it, you divide the blocks first, thanks you!

will not it get TLE? Because the maximum size of the points might be 1e9.

You can use Dijkstra to solve it.

To judge Yes or No, you can traverse every points. If every points can be reached, it's Yes. To print all prev, You need to create a new array ans[] to store the prev of every points(except 1) and update them.