Google Interview Question

Graph and disjoint set related question