Advertisement
mikymaione

Alg_20170628 non funziona

Jul 2nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1.  
  2.         public bool Alg_20170628(int a, int b, int c, int d)
  3.         {
  4.             var time = 0;
  5.             var n_a = get_nodo(a);
  6.             var n_b = get_nodo(b);
  7.             var n_c = get_nodo(c);
  8.             var n_d = get_nodo(d);
  9.  
  10.             Func<Nodo, Nodo, bool> IsAntenato = null;
  11.             IsAntenato = (x, y) =>
  12.             {
  13.                 if (y != null)
  14.                 {
  15.                     if (x == y)
  16.                         return true;
  17.                     else
  18.                         return IsAntenato(x, y.Pred);
  19.                 }
  20.  
  21.                 return false;
  22.             };
  23.  
  24.             Func<Nodo, bool> dfs = null;
  25.             dfs = (u) =>
  26.             {
  27.                 time++;
  28.                 u.discovered = time;
  29.                 u.color = Nodo.Color.Gray;
  30.  
  31.                 foreach (var v in Adj[u])
  32.                     if (v.color == Nodo.Color.White)
  33.                     {
  34.                         v.Pred = u;
  35.  
  36.                         if (!dfs(v))
  37.                             return false;
  38.                     }
  39.                     else if (v.color == Nodo.Color.Gray)
  40.                     {
  41.                         if (n_d != v && IsAntenato(n_d, v))
  42.                             return false;
  43.                     }
  44.  
  45.                 time++;
  46.                 u.finished = time;
  47.                 u.color = Nodo.Color.Black;
  48.  
  49.                 return true;
  50.             };
  51.  
  52.  
  53.             n_b.color = Nodo.Color.Black;
  54.             n_c.color = Nodo.Color.Black;
  55.  
  56.             var r = dfs(n_a);
  57.  
  58.             Console.WriteLine("Nel grafo {0}, {1}esiste un percorso {2} ~> {3} ~> {4} ~> {5}", Nome, (r ? "" : "Non "), a, b, c, d);
  59.  
  60.             return r;
  61.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement