競技プログラミング用のライブラリ    次のライブラリへ    前のライブラリへ

004-01 DFSのテンプレート


DFSのテンプレートです。


C#のソース

    struct JyoutaiDef
    {
        internal int Curr_X;
        internal int Curr_Y;
        internal int Level;
        internal int SumCost;
    }

    static void ExecDFS()
    {
        var Stk = new Stack<JyoutaiDef>();
        JyoutaiDef WillPush;
        WillPush.Curr_X = 1234;
        WillPush.Curr_Y = 1234;
        WillPush.Level = 1234;
        WillPush.SumCost = 1234;
        Stk.Push(WillPush);

        var VisitedSet = new HashSet<int>();

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

            // クリア判定

            Action<int> PushAct = (仮引数名) =>
            {
                int Hash = GetHash(WillPush);
                if (VisitedSet.Add(Hash)) {
                    // Stk.Push(WillPush);
                }
            };

            // Stk.Push(WillPush);
        }
    }

    static int GetHash(JyoutaiDef pJyoutai)
    {
        return pJyoutai.Curr_X * 1234 + pJyoutai.Curr_Y;
    }