Language: C++

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

namespace _20180307_AOJ
{
    class ALDS1_11D
    {
        static Node[] nodes;
        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];

                nodes = new Node[n];
                for(int i=0;i<n;i++)
                {
                    nodes[i] = new Node();
                }
                for(int i=0;i<m;i++)
                {
                    int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    int s = s_t[0];
                    int t = s_t[1];
                    nodes[s].Friends.Add(t);
                    nodes[t].Friends.Add(s);
                }

                int q = int.Parse(Console.ReadLine());
                for(int i=0;i<q;i++)
                {
                    int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    int s = s_t[0];
                    int t = s_t[1];
                    bool isFriend = IsFriend(s, t, new List<int> { s });
                    if(isFriend)
                    {
                        Console.WriteLine("yes");
                    }
                    else
                    {
                        Console.WriteLine("no");
                    }
                }
            }
        }

        static bool IsFriend(int s, int t, List<int> visited)
        {
            bool rv = false;
            Node ns = nodes[s];
            if (ns.Friends.Contains(t))
            {
                rv = true;
            }
            else
            {
                foreach (var v in ns.Friends)
                {
                    if (!visited.Contains(v))
                    {
                        visited.Add(v);
                        rv = IsFriend(v, t, visited);
                        if (rv)
                        {
                            break;
                        }
                    }
                }
            }

            return rv;
        }
        
    }

    class Node
    {
        public HashSet<int> Friends { get; set; }
        public Node()
        {
            Friends = new HashSet<int>();
        }
    }
}



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:16: error: 'Node' does not name a type
   10 |         static Node[] nodes;
      |                ^~~~
a.cc:11:26: error: 'string' has not been declared
   11 |         static void Main(string[] args)
      |                          ^~~~~~
a.cc:11:35: error: expected ',' or '...' before 'args'
   11 |         static void Main(string[] args)
      |                                   ^~~~
a.cc:58:44: error: 'List' has not been declared
   58 |         static bool IsFriend(int s, int t, List<int> visited)
      |                                            ^~~~
a.cc:58:48: error: expected ',' or '...' before '<' token
   58 |         static bool IsFriend(int s, int t, List<int> visited)
      |                                                ^
a.cc:85:6: error: expected ';' after class definition
   85 |     }
      |      ^
      |      ;
a.cc: In static member function 'static void _20180307_AOJ::ALDS1_11D::Main(int*)':
a.cc:15:17: error: 'string' was not declared in this scope
   15 |                 string line = Console.ReadLine();
      |                 ^~~~~~
a.cc:16:42: error: 'line' was not declared in this scope
   16 |                 if (string.IsNullOrEmpty(line))
      |                                          ^~~~
a.cc:21:20: error: structured binding declaration cannot have type 'int'
   21 |                 int[] n_m = line.Split(' ').Select(int.Parse).ToArray();
      |                    ^~
a.cc:21:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:21:20: error: empty structured binding declaration
a.cc:21:23: error: expected initializer before 'n_m'
   21 |                 int[] n_m = line.Split(' ').Select(int.Parse).ToArray();
      |                       ^~~
a.cc:22:25: error: 'n_m' was not declared in this scope
   22 |                 int n = n_m[0];
      |                         ^~~
a.cc:25:17: error: 'nodes' was not declared in this scope
   25 |                 nodes = new Node[n];
      |                 ^~~~~
a.cc:25:29: error: 'Node' does not name a type
   25 |                 nodes = new Node[n];
      |                             ^~~~
a.cc:28:36: error: expected type-specifier before 'Node'
   28 |                     nodes[i] = new Node();
      |                                    ^~~~
a.cc:32:24: error: structured binding declaration cannot have type 'int'
   32 |                     int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      |                        ^~
a.cc:32:24: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:32:24: error: empty structured binding declaration
a.cc:32:27: error: expected initializer before 's_t'
   32 |                     int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      |                           ^~~
a.cc:33:29: error: 's_t' was not declared in this scope
   33 |                     int s = s_t[0];
      |                             ^~~
a.cc:39:25: error: expected primary-expression before 'int'
   39 |                 int q = int.Parse(Console.ReadLine());
      |                         ^~~
a.cc:42:24: error: structured binding declaration cannot have type 'int'
   42 |                     int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      |                        ^~
a.cc:42:24: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:42:24: error: empty structured binding declaration
a.cc:42:27: error: expected initializer before 's_t'
   42 |                     int[] s_t = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      |                           ^~~
a.cc:43:29: error: 's_t' was not declared in this scope
   43 |                     int s = s_t[0];
      |                             ^~~
a.cc:45:56: error: 'List' does not name a type
   45 |                     bool isFriend = IsFriend(s, t, new List<int> { s });
      |                                                        ^~~~
a.cc:45:61: error: expected primary-expression before 'int'
   45 |                     bool isFriend = IsFriend(s, t, new List<int> { s });
      |                                                             ^~~
a.cc:48:25: error: 'Console' was not declared in this scope
   48 |                         Console.WriteLine("yes");
      |                         ^~~~~~~
a.cc:52:25: error: 'Console' was not declared in this scope
   52 |                         Console.WriteLine("no");
      |                         ^~~~~~~
a.cc: In static member function 'static bool _20180307_AOJ::ALDS1_11D::IsFriend(int, int, int)':
a.cc:61:13: error: 'Node' was not declared in this scope
   61 |             Node ns = nodes[s];
      |             ^~~~
a.cc:62:17: error: 'ns' was not declared in this scope; did you mean 's'?
   62 |             if (ns.Friends.Contains(t))
      |                 ^~
      |                 s
a.cc:68:26: error: 'var' was not declared in this scope
   68 |                 foreach (var v in ns.Friends)
      |                          ^~~
a.cc:68:17: error: 'foreach' was not declared in this scope
   68 |                 foreach (var v in ns.Friends)
      |                 ^~~~~~~
a.cc: At global scope:
a.cc:89:15: error: expected ':' before 'HashSet'
   89 |         public HashSet<int> Friends { get; set; }
      |               ^~~~~~~~
      |               :
a.cc:89:16: error: 'HashSet' does not name a type
   89 |         public HashSet<int> Friends { get; set; }
      |                ^~~~~~~
a.cc:90:15: error: expected ':' before 'Node'
   90 |         public Node()
      |               ^~~~~
      |               :
a.cc:94:6: error: expected ';' after class definition
   94 |     }
      |      ^
      |      ;
a.cc: In constructor '_20180307_AOJ::Node::Node()':
a.cc:92:13: error: 'Friends' was not declared in this scope; did you mean 'friend'?
   92 |             Friends = new HashSet<int>();
      |             ^~~~~~~
      |             friend
a.cc:92:27: error: 'HashSet' does not name a type
   92 |             Friends = new HashSet<int>();
      |                           ^~~~~~~
a.cc:92:35: error: expected primary-expression before 'int'
   92 |             Friends = new HashSet<int>();
      |                                   ^~~