Language: C++

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20180319_AOJ
{
    class ALDS1_11D
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                int[] n_m = line.Split(' ').Select(int.Parse).ToArray();
                int n = n_m[0];
                int m = n_m[1];
                int[,] matrix = new int[n, n];

                for (int i = 0; i < m; i++)
                {
                    int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    matrix[s_t[0], s_t[1]] = 1;
                    matrix[s_t[1], s_t[0]] = 1;
                }

                int[] group = new int[n];
                int gn = 0;
                for (int i = 0; i < n; i++)
                {
                    if (group[i] == 0)
                    {
                        gn++;
                        group[i] = gn;
                    }

                    gn = group[i];
                    for (int t = 0; t < n; t++)
                    {
                        if (matrix[i, t] == 1)
                        {
                            int tn = group[t];
                            if (tn > 0)
                            {
                                Replace(group, tn, gn);
                            }
                            else
                            {
                                group[t] = gn;
                            }
                        }
                    }
                }

                int q = int.Parse(Console.ReadLine());
                for (int i = 0; i < q; i++)
                {
                    int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    if (group[s_t[0]] == group[s_t[1]])
                    {
                        Console.WriteLine("yes");
                    }
                    else
                    {
                        Console.WriteLine("no");
                    }
                }
            }
        }

        static void Replace<T>(T[] arr, T source, T dest)
        {
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i].Equals(source))
                {
                    arr[i] = dest;
                }
            }
        }
    }
}



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.Linq;
      |       ^~~~~~
a.cc:4:7: error: expected nested-name-specifier before 'System'
    4 | using System.Text;
      |       ^~~~~~
a.cc:10:26: error: 'string' has not been declared
   10 |         static void Main(string[] args)
      |                          ^~~~~~
a.cc:10:35: error: expected ',' or '...' before 'args'
   10 |         static void Main(string[] args)
      |                                   ^~~~
a.cc:76:21: error: variable or field 'Replace' declared void
   76 |         static void Replace<T>(T[] arr, T source, T dest)
      |                     ^~~~~~~
a.cc:76:21: error: expected ';' at end of member declaration
   76 |         static void Replace<T>(T[] arr, T source, T dest)
      |                     ^~~~~~~
      |                            ;
a.cc:76:28: error: expected unqualified-id before '<' token
   76 |         static void Replace<T>(T[] arr, T source, T dest)
      |                            ^
a.cc:86:6: error: expected ';' after class definition
   86 |     }
      |      ^
      |      ;
a.cc: In static member function 'static void _20180319_AOJ::ALDS1_11D::Main(int*)':
a.cc:14:17: error: 'string' was not declared in this scope
   14 |                 string line = Console.ReadLine();
      |                 ^~~~~~
a.cc:15:42: error: 'line' was not declared in this scope
   15 |                 if (string.IsNullOrEmpty(line))
      |                                          ^~~~
a.cc:20:20: error: structured binding declaration cannot have type 'int'
   20 |                 int[] n_m = line.Split(' ').Select(int.Parse).ToArray();
      |                    ^~
a.cc:20:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:20:20: error: empty structured binding declaration
a.cc:20:23: error: expected initializer before 'n_m'
   20 |                 int[] n_m = line.Split(' ').Select(int.Parse).ToArray();
      |                       ^~~
a.cc:21:25: error: 'n_m' was not declared in this scope
   21 |                 int n = n_m[0];
      |                         ^~~
a.cc:23:21: error: expected identifier before ',' token
   23 |                 int[,] matrix = new int[n, n];
      |                     ^
a.cc:23:21: error: expected ']' before ',' token
a.cc:23:20: error: structured binding declaration cannot have type 'int'
   23 |                 int[,] matrix = new int[n, n];
      |                    ^
a.cc:23:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:23:20: error: empty structured binding declaration
a.cc:23:24: error: expected initializer before 'matrix'
   23 |                 int[,] matrix = new int[n, n];
      |                        ^~~~~~
a.cc:27:24: error: structured binding declaration cannot have type 'int'
   27 |                     int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      |                        ^~
a.cc:27:24: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:27:24: error: empty structured binding declaration
a.cc:27:27: error: expected initializer before 's_t'
   27 |                     int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      |                           ^~~
a.cc:28:21: error: 'matrix' was not declared in this scope
   28 |                     matrix[s_t[0], s_t[1]] = 1;
      |                     ^~~~~~
a.cc:28:28: error: 's_t' was not declared in this scope
   28 |                     matrix[s_t[0], s_t[1]] = 1;
      |                            ^~~
a.cc:32:20: error: structured binding declaration cannot have type 'int'
   32 |                 int[] group = new int[n];
      |                    ^~
a.cc:32:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:32:20: error: empty structured binding declaration
a.cc:32:23: error: expected initializer before 'group'
   32 |                 int[] group = new int[n];
      |                       ^~~~~
a.cc:36:25: error: 'group' was not declared in this scope
   36 |                     if (group[i] == 0)
      |                         ^~~~~
a.cc:42:26: error: 'group' was not declared in this scope
   42 |                     gn = group[i];
      |                          ^~~~~
a.cc:45:29: error: 'matrix' was not declared in this scope
   45 |                         if (matrix[i, t] == 1)
      |                             ^~~~~~
a.cc:50:33: error: 'Replace' was not declared in this scope
   50 |                                 Replace(group, tn, gn);
      |                                 ^~~~~~~
a.cc:60:25: error: expected primary-expression before 'int'
   60 |                 int q = int.Parse(Console.ReadLine());
      |                         ^~~
a.cc:63:24: error: structured binding declaration cannot have type 'int'
   63 |                     int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      |                        ^~
a.cc:63:24: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:63:24: error: empty structured binding declaration
a.cc:63:27: error: expected initializer before 's_t'
   63 |                     int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      |                           ^~~
a.cc:64:25: error: 'group' was not declared in this scope
   64 |                     if (group[s_t[0]] == group[s_t[1]])
      |                         ^~~~~
a.cc:64:31: error: 's_t' was not declared in this scope
   64 |                     if (group[s_t[0]] == group[s_t[1]])
      |                               ^~~
a.cc:66:25: error: 'Console' was not declared in this scope
   66 |                         Console.WriteLine("yes");
      |                         ^~~~~~~
a.cc:70:25: error: 'Console' was not declared in this scope
   70 |                         Console.WriteLine("no");
      |                         ^~~~~~~