Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool Alg_20170628(int a, int b, int c, int d)
- {
- var time = 0;
- var n_a = get_nodo(a);
- var n_b = get_nodo(b);
- var n_c = get_nodo(c);
- var n_d = get_nodo(d);
- Func<Nodo, Nodo, bool> IsAntenato = null;
- IsAntenato = (x, y) =>
- {
- if (y != null)
- {
- if (x == y)
- return true;
- else
- return IsAntenato(x, y.Pred);
- }
- return false;
- };
- Func<Nodo, bool> dfs = null;
- dfs = (u) =>
- {
- time++;
- u.discovered = time;
- u.color = Nodo.Color.Gray;
- foreach (var v in Adj[u])
- if (v.color == Nodo.Color.White)
- {
- v.Pred = u;
- if (!dfs(v))
- return false;
- }
- else if (v.color == Nodo.Color.Gray)
- {
- if (n_d != v && IsAntenato(n_d, v))
- return false;
- }
- time++;
- u.finished = time;
- u.color = Nodo.Color.Black;
- return true;
- };
- n_b.color = Nodo.Color.Black;
- n_c.color = Nodo.Color.Black;
- var r = dfs(n_a);
- Console.WriteLine("Nel grafo {0}, {1}esiste un percorso {2} ~> {3} ~> {4} ~> {5}", Nome, (r ? "" : "Non "), a, b, c, d);
- return r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement