Language: C++

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

class Program
{
    static string InputPattern = "Input2";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5 4");
            WillReturn.Add("0 0 0 0 0");
            WillReturn.Add("0 1 1 0 0");
            WillReturn.Add("0 0 1 0 1");
            WillReturn.Add("1 0 0 0 1");
            WillReturn.Add("5 4");
            WillReturn.Add("0 0 0 0 0");
            WillReturn.Add("0 1 1 0 0");
            WillReturn.Add("0 0 0 0 1");
            WillReturn.Add("1 0 0 0 1");
            WillReturn.Add("0 0");
            //Yes 
            //No 
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        InputList.RemoveAt(InputList.Count - 1);

        var InputIntArrList = new List<int[]>();
        foreach (string EachStr in InputList) {
            int[] WillAdd = EachStr.Split(' ').Select(X => int.Parse(X)).ToArray();
            InputIntArrList.Add(WillAdd);
        }

        //碁盤の2次元配列のListを作成 
        //List<int[,]> BanArrList = CreateBanArrList(InputIntArrList);

        //BanArrList.ForEach(X => Console.WriteLine(CanHeikyokusen(X) ? "Yes" : "No"));
    }

    //碁盤の2次元配列のListを作成 
    static List<int[,]> CreateBanArrList(List<int[]> pInputIntArrList)
    {
        var BanArrList = new List<int[,]>();
        var wkLineIntList = new List<int[]>();

        int RestHeight = 0;
        foreach (int[] EachIntArr in pInputIntArrList) {
            if (RestHeight == 0) {
                RestHeight = EachIntArr[1];
                continue;
            }

            wkLineIntList.Add(EachIntArr);

            if (--RestHeight == 0) {
                int[,] wkArr = new int[wkLineIntList[0].GetUpperBound(0) + 1,
                                       wkLineIntList.Count];
                for (int Y = 0; Y <= wkLineIntList.Count - 1; Y++) {
                    for (int X = 0; X <= wkLineIntList[Y].GetUpperBound(0); X++) {
                        wkArr[X, Y] = wkLineIntList[Y][X];
                    }
                }
                BanArrList.Add(wkArr);
                wkLineIntList.Clear();
            }
        }
        return BanArrList;
    }

    struct JyoutaiDef
    {
        internal int CurrX;
        internal int CurrY;
        internal List<string> VisitedList;
    }

    //閉曲線を描くことが可能な遺跡かを返す 
    static bool CanHeikyokusen(int[,] pBanArr)
    {
        //石像のないマスの数 
        int NonSekizouMasuCnt = pBanArr.Cast<int>().Count(X => X == 0);
        if (NonSekizouMasuCnt == 0) return false;

        int UB_X = pBanArr.GetUpperBound(0);
        int UB_Y = pBanArr.GetUpperBound(1);

        //石像のないマスから探索開始 
        int StaX = -1, StaY = -1;
        Action wkAct = () =>
        {
            for (int X = 0; X <= UB_X; X++) {
                for (int Y = 0; Y <= UB_Y; Y++) {
                    if (pBanArr[X, Y] == 0) {
                        StaX = X; StaY = Y;
                        return;
                    }
                }
            }
        };
        wkAct();

        var stk = new Stack<JyoutaiDef>();
        JyoutaiDef WillPush;
        WillPush.CurrX = StaX;
        WillPush.CurrY = StaY;
        WillPush.VisitedList = new List<string>();
        WillPush.VisitedList.Add(string.Format("({0},{1})", StaX, StaY));
        stk.Push(WillPush);

        while (stk.Count > 0) {
            JyoutaiDef Popped = stk.Pop();

            //クリア判定 
            if (Popped.VisitedList.Count == NonSekizouMasuCnt) {
                //探索開始座標とのマンハッタン距離
                int Kyori = Math.Abs(Popped.CurrX - StaX)
                          + Math.Abs(Popped.CurrY - StaY);
                if (Kyori > 1) continue;

                return true;
            }

            //Push処理 
            Action<int, int> PushSyori = (pX, pY) =>
            {
                if (pX < 0 || UB_X < pX) return;
                if (pY < 0 || UB_Y < pY) return;

                //石像なら訪問不可 
                if (pBanArr[pX, pY] == 1) return;

                //再訪不可 
                string VisitStr = string.Format("({0},{1})", pX, pY);
                if (Popped.VisitedList.Contains(VisitStr)) return;

                WillPush.CurrX = pX;
                WillPush.CurrY = pY;
                WillPush.VisitedList = new List<string>(Popped.VisitedList);
                WillPush.VisitedList.Add(VisitStr);
                stk.Push(WillPush);
            };
            PushSyori(Popped.CurrX, Popped.CurrY - 1);
            PushSyori(Popped.CurrX, Popped.CurrY + 1);
            PushSyori(Popped.CurrX - 1, Popped.CurrY);
            PushSyori(Popped.CurrX + 1, Popped.CurrY);
        }
        return false;
    }
}

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:7:12: error: 'string' does not name a type
    7 |     static string InputPattern = "Input2";
      |            ^~~~~~
a.cc:9:12: error: 'List' does not name a type
    9 |     static List<string> GetInputList()
      |            ^~~~
a.cc:53:12: error: 'List' does not name a type
   53 |     static List<int[,]> CreateBanArrList(List<int[]> pInputIntArrList)
      |            ^~~~
a.cc:84:9: error: 'internal' does not name a type
   84 |         internal int CurrX;
      |         ^~~~~~~~
a.cc:85:9: error: 'internal' does not name a type
   85 |         internal int CurrY;
      |         ^~~~~~~~
a.cc:86:9: error: 'internal' does not name a type
   86 |         internal List<string> VisitedList;
      |         ^~~~~~~~
a.cc:87:6: error: expected ';' after struct definition
   87 |     }
      |      ^
      |      ;
a.cc:90:36: error: expected primary-expression before ',' token
   90 |     static bool CanHeikyokusen(int[,] pBanArr)
      |                                    ^
a.cc:90:36: error: expected ']' before ',' token
   90 |     static bool CanHeikyokusen(int[,] pBanArr)
      |                                    ^
      |                                    ]
a.cc:90:36: error: expected ')' before ',' token
   90 |     static bool CanHeikyokusen(int[,] pBanArr)
      |                               ~    ^
      |                                    )
a.cc:90:37: error: expected unqualified-id before ']' token
   90 |     static bool CanHeikyokusen(int[,] pBanArr)
      |                                     ^
a.cc:161:2: error: expected ';' after class definition
  161 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Program::Main()':
a.cc:37:9: error: 'List' was not declared in this scope
   37 |         List<string> InputList = GetInputList();
      |         ^~~~
a.cc:37:14: error: 'string' was not declared in this scope
   37 |         List<string> InputList = GetInputList();
      |              ^~~~~~
a.cc:37:22: error: 'InputList' was not declared in this scope
   37 |         List<string> InputList = GetInputList();
      |                      ^~~~~~~~~
a.cc:37:34: error: 'GetInputList' was not declared in this scope
   37 |         List<string> InputList = GetInputList();
      |                                  ^~~~~~~~~~~~
a.cc:40:9: error: 'var' was not declared in this scope
   40 |         var InputIntArrList = new List<int[]>();
      |         ^~~
a.cc:41:25: error: expected ')' before 'EachStr'
   41 |         foreach (string EachStr in InputList) {
      |                         ^~~~~~~
a.cc:41:17: note: to match this '('
   41 |         foreach (string EachStr in InputList) {
      |                 ^
a.cc:41:9: error: 'foreach' was not declared in this scope
   41 |         foreach (string EachStr in InputList) {
      |         ^~~~~~~