Language: C++

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace _20190304_06 {
    class Program {
        static void Main(string[] args) {
            var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var n = line[0];
            var m = line[1];
            var bridgeList = new int[m, 2];
            for (int i = 0; i < m; i++) {
                var bridge = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                bridgeList[m - i - 1, 0] = bridge[0];
                bridgeList[m - i - 1, 1] = bridge[1];
            }
            var groups = 1;
            var islands = Enumerable.Repeat(0, n).ToArray();
            var answer = new int[m];
            var max = mC2(n);
            answer[m - 1] = max;
            for (int i = 0; i < m - 1; i++) {
                var i1 = bridgeList[i, 0] - 1;
                var i2 = bridgeList[i, 1] - 1;
                if (islands[i1] == 0 && islands[i2] == 0) {
                    islands[i1] = groups;
                    islands[i2] = groups;
                    groups++;
                    answer[m - i - 2] = answer[m - i - 1] - 1;
                } else if (islands[i1] == 0 && islands[i2] != 0) {
                    answer[m - i - 2] = answer[m - i - 1] - islands.Where(x => x == islands[i2]).Count();
                    islands[i1] = islands[i2];
                } else if (islands[i1] != 0 && islands[i2] == 0) {
                    answer[m - i - 2] = answer[m - i - 1] - islands.Where(x => x == islands[i1]).Count();
                    islands[i2] = islands[i1];
                } else if (islands[i1] != islands[i2]) {
                    answer[m - i - 2] = answer[m - i - 1] - islands.Where(x => x == islands[i1]).Count() * islands.Where(x => x == islands[i2]).Count();
                    var index = islands[i2];
                    for (int j = 0; j < n; j++) {
                        if (islands[j] == index) {
                            islands[j] = islands[i1];
                        }
                    }
                }
            }
            foreach (var a in answer) {
                Console.WriteLine(a);
            }
        }

        static int mC2(int m) {
            return m * (m - 1) / 2;
        }
    }
}

Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.Diagnostics;
      |       ^~~~~~
a.cc:4:7: error: expected nested-name-specifier before 'System'
    4 | using System.Linq;
      |       ^~~~~~
a.cc:8:26: error: 'string' has not been declared
    8 |         static void Main(string[] args) {
      |                          ^~~~~~
a.cc:8:35: error: expected ',' or '...' before 'args'
    8 |         static void Main(string[] args) {
      |                                   ^~~~
a.cc:55:6: error: expected ';' after class definition
   55 |     }
      |      ^
      |      ;
a.cc: In static member function 'static void _20190304_06::Program::Main(int*)':
a.cc:9:13: error: 'var' was not declared in this scope
    9 |             var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
      |             ^~~
a.cc:10:17: error: expected ';' before 'n'
   10 |             var n = line[0];
      |                 ^
a.cc:11:17: error: expected ';' before 'm'
   11 |             var m = line[1];
      |                 ^
a.cc:12:17: error: expected ';' before 'bridgeList'
   12 |             var bridgeList = new int[m, 2];
      |                 ^~~~~~~~~~
a.cc:13:33: error: 'm' was not declared in this scope
   13 |             for (int i = 0; i < m; i++) {
      |                                 ^
a.cc:14:21: error: expected ';' before 'bridge'
   14 |                 var bridge = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
      |                     ^~~~~~
a.cc:15:17: error: 'bridgeList' was not declared in this scope
   15 |                 bridgeList[m - i - 1, 0] = bridge[0];
      |                 ^~~~~~~~~~
a.cc:15:44: error: 'bridge' was not declared in this scope
   15 |                 bridgeList[m - i - 1, 0] = bridge[0];
      |                                            ^~~~~~
a.cc:18:17: error: expected ';' before 'groups'
   18 |             var groups = 1;
      |                 ^~~~~~
a.cc:19:17: error: expected ';' before 'islands'
   19 |             var islands = Enumerable.Repeat(0, n).ToArray();
      |                 ^~~~~~~
a.cc:20:17: error: expected ';' before 'answer'
   20 |             var answer = new int[m];
      |                 ^~~~~~
a.cc:21:17: error: expected ';' before 'max'
   21 |             var max = mC2(n);
      |                 ^~~
a.cc:22:13: error: 'answer' was not declared in this scope
   22 |             answer[m - 1] = max;
      |             ^~~~~~
a.cc:22:20: error: 'm' was not declared in this scope
   22 |             answer[m - 1] = max;
      |                    ^
a.cc:22:29: error: 'max' was not declared in this scope
   22 |             answer[m - 1] = max;
      |                             ^~~
a.cc:24:21: error: expected ';' before 'i1'
   24 |                 var i1 = bridgeList[i, 0] - 1;
      |                     ^~
a.cc:25:21: error: expected ';' before 'i2'
   25 |                 var i2 = bridgeList[i, 1] - 1;
      |                     ^~
a.cc:26:21: error: 'islands' was not declared in this scope
   26 |                 if (islands[i1] == 0 && islands[i2] == 0) {
      |                     ^~~~~~~
a.cc:26:29: error: 'i1' was not declared in this scope; did you mean 'i'?
   26 |                 if (islands[i1] == 0 && islands[i2] == 0) {
      |                             ^~
      |                             i
a.cc:26:49: error: 'i2' was not declared in this scope; did you mean 'i'?
   26 |                 if (islands[i1] == 0 && islands[i2] == 0) {
      |                                                 ^~
      |                                                 i
a.cc:27:35: error: 'groups' was not declared in this scope
   27 |                     islands[i1] = groups;
      |                                   ^~~~~~
a.cc:32:75: error: 'x' was not declared in this scope
   32 |                     answer[m - i - 2] = answer[m - i - 1] - islands.Where(x => x == islands[i2]).Count();
      |                                                                           ^
a.cc:32:78: error: expected primary-expression before '>' token
   32 |                     answer[m - i - 2] = answer[m - i - 1] - islands.Where(x => x == islands[i2]).Count();
      |                                                                              ^
a.cc:35:75: error: 'x' was not declared in this scope
   35 |                     answer[m - i - 2] = answer[m - i - 1] - islands.Where(x => x == islands[i1]).Count();
      |                                                                           ^
a.cc:35:78: error: expected primary-expression before '>' token
   35 |                     answer[m - i - 2] = answer[m - i - 1] - islands.Where(x => x == islands[i1]).Count();
      |                                                                              ^
a.cc:38:75: error: 'x' was not declared in this scope
   38 |                     answer[m - i - 2] = answer[m - i - 1] - islands.Where(x => x == islands[i1]).Count() * islands.Where(x => x == islands[i2]).Count();
      |                                                                           ^
a.cc:38:78: error: expected primary-expression before '>' token
   38 |                     answer[m - i - 2] = answer[m - i - 1] - islands.Where(x => x == islands[i1]).Count() * islands.Where(x => x == islands[i2]).Count();
      |                                                                              ^
a.cc:38:125: error: expected primary-expression before '>' token
   38 |                     answer[m - i - 2] = answer[m - i - 1] - islands.Where(x => x == islands[i1]).Count() * islands.Where(x => x == islands[i2]).Count();
      |                                                                                                                             ^
a.cc:39:25: error: expected ';' before 'index'
   39 |                     var index = islands[i2];
      |                         ^~~~~
a.cc:40:41: error: 'n' was not declared in this scope
   40 |                     for (int j = 0; j < n; j++) {
      |                                         ^
a.cc:41:43: error: 'index' was not declared in this scope
   41 |                         if (islands[j] == index) {
      |                                           ^~~~~
a.cc:47:26: error: expected ')' before 'a'
   47 |             foreach (var a in answer) {
      |                          ^
a.cc:47:21: note: to match this '('
   47 |             foreach (var a in answer) {
      |                     ^
a.cc:47:13: error: 'foreach' was not declared in this scope
   47 |             foreach (var a in answer) {
      |             ^~~~~~~