예제 #1
0
        //Parcurgerea in latime
        public void PL(int nStart)
        {
            for (int i = 0; i < n; i++)
            {
                b[i] = false;
            }
            b[nStart] = true;

            Coada c = new Coada();

            c.Add(nStart);
            listBox1.Items.Add((nStart + 1) + " ");

            while (c.n != 0)
            {
                int v = c.Delete();
                for (int i = 0; i < n; i++)
                {
                    if (ma[v, i] == 1 && !b[i])
                    {
                        c.Add(i);
                        b[i] = true;
                        listBox1.Items.Add((i + 1) + " ");
                    }
                }
            }
        }
예제 #2
0
        public bool Bipartit()
        {
            int[] colors = new int[n];
            for (int i = 0; i < n; i++)
            {
                b[i] = false;
            }

            Coada c = new Coada();

            c.Add(0);
            b[0]      = true;
            colors[0] = 1;

            while (c.n != 0)
            {
                int value = c.Delete();
                for (int i = 0; i < n; i++)
                {
                    if (ma[value, i] == 1)
                    {
                        if (!b[i])
                        {
                            colors[i] = colors[value] % 2 + 1; // 1 sau 2
                            b[i]      = true;
                            c.Add(i);
                        }
                        else
                        {
                            if (colors[i] != colors[value] % 2 + 1)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }