Not working for 3 test cases

@akshitmehta I don’t think there is any code in this link. Anyways I would recommend you to use dsu in this problem. Find he sizes of all components and then multiplying them would give you the results

i did that too there is a code in this link https://ide.codingblocks.com/s/234819 still getting wrong answer

Where are you finding the connected components? You should use disjoint sets Union or use dfs or bfs to find the size and number of components