Language: Java

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int a[][] = new int[m][2];
            for (int i = 0; i < m; i++) {
                a[i][0] = in.nextInt();
                a[i][1] = in.nextInt();
            }
            DSet d = new DSet(n);
            long temp = (n * (n - 1)) / 2;
            ArrayList<Long> ans = new ArrayList<>();
            ans.add(temp);
            for (int i = m - 1; i >= 0; i--) {
                int p = d.size;
                long temp2 = (long) d.csize[d.find(a[i][0])] * (long) d.csize[d.find(a[i][1])];
//            out.println(d.csize[d.find(a[i][0])] + " " + d.csize[d.find(a[i][1])]);
                d.union(a[i][0], a[i][1]);
                int q = d.size;
                if (p != q) {
                    temp -= temp2;
                }
                ans.add(temp);
            }
            for (int i = m - 1; i >= 0; i--) {
                out.println(ans.get(i));
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class DSet {
        int parent;
        int rank;
        int csize;
        int size;

        DSet(int n) {
            parent = new int[n + 1];
            rank = new int[n + 1];
            csize = new int[n + 1];
            size = n;
            for (int i = 0; i <= n; i++) {
                this.parent[i] = i;
                this.csize[i] = 1;
            }
        }

        public int find(int i) {
            if (parent[i] == i) return i;
            else {
                int result = find(parent[i]);
                parent[i] = result;
                return result;
            }
        }

        public void union(int i, int j) {
            int ipar = this.find(i);
            int jpar = this.find(j);
            if (ipar == jpar) {
                return;
            }
            int irank = this.rank[ipar];
            int jrank = this.rank[jpar];
            if (irank < jrank) {
                this.parent[ipar] = jpar;
                this.csize[jpar] += this.csize[ipar];
            } else if (jrank < irank) {
                this.parent[jpar] = ipar;
                this.csize[ipar] += this.csize[jpar];
            } else {
                this.parent[ipar] = jpar;
                this.csize[jpar] += this.csize[ipar];
                this.rank[jpar]++;
            }
            size--;
        }

    }
}



Compiler output:
Main.java:44: error: array required, but int found
                long temp2 = (long) d.csize[d.find(a[i][0])] * (long) d.csize[d.find(a[i][1])];
                                           ^
Main.java:44: error: array required, but int found
                long temp2 = (long) d.csize[d.find(a[i][0])] * (long) d.csize[d.find(a[i][1])];
                                                                             ^
Main.java:93: error: incompatible types: int[] cannot be converted to int
            parent = new int[n + 1];
                     ^
Main.java:94: error: incompatible types: int[] cannot be converted to int
            rank = new int[n + 1];
                   ^
Main.java:95: error: incompatible types: int[] cannot be converted to int
            csize = new int[n + 1];
                    ^
Main.java:98: error: array required, but int found
                this.parent[i] = i;
                           ^
Main.java:99: error: array required, but int found
                this.csize[i] = 1;
                          ^
Main.java:104: error: array required, but int found
            if (parent[i] == i) return i;
                      ^
Main.java:106: error: array required, but int found
                int result = find(parent[i]);
                                        ^
Main.java:107: error: array required, but int found
                parent[i] = result;
                      ^
Main.java:118: error: array required, but int found
            int irank = this.rank[ipar];
                                 ^
Main.java:119: error: array required, but int found
            int jrank = this.rank[jpar];
                                 ^
Main.java:121: error: array required, but int found
                this.parent[ipar] = jpar;
                           ^
Main.java:122: error: array required, but int found
                this.csize[jpar] += this.csize[ipar];
                          ^
Main.java:122: error: array required, but int found
                this.csize[jpar] += this.csize[ipar];
                                              ^
Main.java:124: error: array required, but int found
                this.parent[jpar] = ipar;
                           ^
Main.java:125: error: array required, but int found
                this.csize[ipar] += this.csize[jpar];
                          ^
Main.java:125: error: array required, but int found
                this.csize[ipar] += this.csize[jpar];
                                              ^
Main.java:127: error: array required, but int found
                this.parent[ipar] = jpar;
                           ^
Main.java:128: error: array required, but int found
                this.csize[jpar] += this.csize[ipar];
                          ^
Main.java:128: error: array required, but int found
                this.csize[jpar] += this.csize[ipar];
                                              ^
Main.java:129: error: array required, but int found
                this.rank[jpar]++;
                         ^
22 errors