I am using networkx package of Python.
Using a disjoint set data structure:
Create a singleton set for every vertex in the graph, then union the sets containing each of the pair of vertices for every edge in the graph.
Finally, you know a path exists between two vertices if they are in the same set.
See the wikipedia page on the disjoint set data structure.
This is much more efficient than using a path finding algorithm.