public static void Main(string[] args) { var G = new Digraph(new StreamReader(args[0])); var sources = new List <int>(); for (int i = 1; i < args.Length; i++) { sources.Add(int.Parse(args[i])); } var reachable = new DirectedDFS(G, sources); for (int v = 0; v < G.V; v++) { if (reachable.Marked[v]) { Console.Write(v + " "); } Console.WriteLine(); } }
public SymbolGraph(string stream, char sp) { dic = new Dictionary <string, int>(); using (var reader = new StreamReader(stream)) { while (reader.Peek() > -1) { var a = reader.ReadLine().Split(sp); for (int i = 0; i < a.Length; i++) { if (!dic.ContainsKey(a[i])) { dic.Add(a[i], dic.Count); } } } keys = new string[dic.Count]; foreach (var item in dic) { keys[item.Value] = item.Key; } G = new Graph(dic.Count); DirG = new Digraph(dic.Count); reader.BaseStream.Seek(0, SeekOrigin.Begin); while (reader.Peek() > -1) { var a = reader.ReadLine().Split(sp); var v = dic[a[0]]; for (int i = 1; i < a.Length; i++) { G.AddEdge(v, dic[a[i]]); DirG.AddEdge(v, dic[a[i]]); } } } }
public DirectedDFS(Digraph G, int s) { Marked = new bool[G.V]; DFS(G, s); }