Пример #1
0
 private void DFS(Graph G, int v)
 {
     marked[v] = true;
     id[v] = count;
     foreach (var w in G.Adj(v))
         if (!marked[w])
             DFS(G, w);
 }
Пример #2
0
 private void DFS(Graph G, int v)
 {
     marked[v] = true;
     foreach (var w in G.Adj(v))
     {
         if (!marked[w])
         {
             DFS(G, w);
             edgeTo[w] = v;
         }
     }
 }
Пример #3
0
 private static bool DFS( Graph G,int v,  ref List<int> G1, ref List<int> G2, byte mark)
 {
     marked[v] = mark;
     G1.Add(v);
     bool result = true;
     foreach (var w in G.Adj(v))
     {
         if (marked[w] != 0 && marked[w] == mark) return false;
         if (marked[w] == 0)
         {
             result = result && DFS(G, w, ref G2, ref G1, mark == FIRST? SECOND: FIRST);
         }
     }
     return result;
 }
Пример #4
0
        private void BFS(Graph G, IEnumerable<int> sources)
        {
            Queue<int> q = new Queue<int>();
            foreach (int source in sources)
            {
                q.Enqueue(source);
            }

            while (!(q.Count == 0))
            {
                int v = q.Dequeue();
                foreach (int w in G.Adj(v))
                {
                    if (!marked[w])
                    {
                        q.Enqueue(w);
                        marked[w] = true;
                        edgeTo[w] = v;
                    }
                }
            }
        }
Пример #5
0
 public void Graph_API_Test()
 {
     Graph G = new Graph(3);
     G.AddEdge(0, 1);
     G.AddEdge(0, 2);
     List<int> e = new List<int>(G.Adj(0));
     Assert.AreEqual(1, e[0]);
 }