For this Question: You are given N nodes and M undirected edges. These nodes and edges represent some trees (graphs with no loops). Now, your task is to merge the trees into a single tree. In one operation of merging, two disconnected trees are merged using an edge from one tree to the other tree. The cost of this merging operation is <b>total number of nodes in the final merged tree</b>. Once merged the trees lose their original existence. 
So, if there are T trees in the original state, you'll have to perform the merge operation T-1 times to merge all the trees in a single tree.

All you need to do is find the minimum cost of merging the trees (sum of costs of all T-1 merge operations). See sample for better understanding.The first line of input contains two integers N and M, the total number of nodes and the total number of edges.
The next M lines contain two integers U and V, representing an undirected edge between the two nodes.

Constraints
1 <= N <= 200000
0 <= M < N
1 <= U, V <= N
The given nodes and edges represent some trees (maybe 1)Output a single integer, the cost of merging these trees.Sample Input
7 3
1 2
3 4
4 5

Sample Output
13

Explanation: 
The four trees are as follows:
1 --- 2 ; 3 --- 4 --- 5 ; 6 ; 7
We will first add an edge from 6 to 7. (Cost of merging = 2)
The three remaining trees are as follows:
1 --- 2 ; 3 --- 4 --- 5 ; 6 --- 7
We will add an edge from 2 to 6. (Cost of merging = 4)
The two remaining trees are as follows:
1 --- 2 --- 6 --- 7 ; 3 --- 4 --- 5
We will add an edge from 7 to 3. (Cost of merging = 7)
Total cost of merging = 2 + 4 + 7 = 13.

Sample Input
2 1
1 2

Sample Output
0, I have written this Solution Code: import java.io.*;
import java.util.*;


class Main {
    static int  find(int []parent, int x){
        if(parent[x] == x){
            return x;
        }
        parent[x] = find(parent, parent[x]);
        return parent[x];
    }
    static void union(int []parent, int x, int y){
        int parentX = find(parent, x);
        int parentY = find(parent, y);
        parent[parentY] = parentX;
    }
    public static void main (String[] args)throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().trim().split(" ");
        int N = Integer.parseInt(str[0]);
        int M = Integer.parseInt(str[1]);
        int totalCost = 0;
        int[] parent = new int[N+1];
        for(int i=1; i<=N; i++){
            parent[i] = i;
        }
        for (int i=0; i<M; i++) {
            int x, y;
            String[] str1 = br.readLine().trim().split(" ");
            x = Integer.parseInt(str1[0]);
            y =  Integer.parseInt(str1[1]);
            union(parent, x, y);
        }
        for(int i=1; i<=N; i++){
            find(parent, i);
        }
        PriorityQueue<Integer> pQueue = new PriorityQueue<Integer>();
        HashMap<Integer, Integer> counts = new HashMap<>();
        for(int i=1; i<=N; i++){
            counts.put(parent[i], counts.getOrDefault(parent[i], 0) + 1);
        }
        for (Map.Entry<Integer,Integer> entry : counts.entrySet()) {
            pQueue.add(entry.getValue());
        }
        while(pQueue.size() > 1) {
            int s1 = pQueue.poll();
            int s2 = pQueue.poll();
            totalCost += s1 + s2;
            pQueue.add(s1 + s2);
        }
        System.out.println(totalCost);
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?