private static List <string> FindCheatersList(Dictionary <string, Dictionary <string, List <Node> > > allgraph, string name, string subject) { var subjectGraph = BuildSubjectGraphForName(allgraph, subject, name); var graph = new Dictionary <string, TopoNode>(); foreach (var pair in subjectGraph) { if (graph.ContainsKey(pair.Key) == false) { graph[pair.Key] = new TopoNode(pair.Key); } foreach (var child in pair.Value) { if (graph.ContainsKey(child) == false) { graph[child] = new TopoNode(child); } ++graph[child].ParentsCount; graph[pair.Key].Add(child); } } var result = TopologicalSort(graph); return(result); }
static Dictionary <char, TopoNode> ReadDirectedGraph() { var n = int.Parse(Console.ReadLine()); var vertices = new Dictionary <char, TopoNode>(); var set = new SortedSet <string>(); for (var i = 0; i < n; i++) { var line = Console.ReadLine(); if (line.Length == 1) { var x = line[0]; if (vertices.ContainsKey(x) == false) { vertices[x] = new TopoNode { ParentsCount = 0, Children = new LinkedList <char>(), }; } } for (int j = 0; j < line.Length - 1; j++) { var x = line[j]; var y = line[j + 1]; if (vertices.ContainsKey(x) == false) { vertices[x] = new TopoNode { ParentsCount = 0, Children = new LinkedList <char>(), }; } if (vertices.ContainsKey(y) == false) { vertices[y] = new TopoNode { ParentsCount = 0, Children = new LinkedList <char>(), }; } vertices[x].Children.AddLast(y); vertices[y].ParentsCount++; } } return(vertices); }
static Dictionary <int, TopoNode> ReadDirectedGraph() { // var n = int.Parse(Console.ReadLine()); // var m = int.Parse(Console.ReadLine()); int n = int.Parse(Console.ReadLine()); var vertices = new Dictionary <int, TopoNode>(); for (var i = 0; i < n; i++) { var edge = Console.ReadLine() .Split(' '); var x = edge[2] == "before" ? int.Parse(edge[0]) : int.Parse(edge[3]); var y = edge[2] == "before" ? int.Parse(edge[3]) : int.Parse(edge[0]); if (vertices.ContainsKey(x) == false) { vertices[x] = new TopoNode { ParentsCount = 0, Children = new LinkedList <int>(), }; } if (vertices.ContainsKey(y) == false) { vertices[y] = new TopoNode { ParentsCount = 0, Children = new LinkedList <int>(), }; } vertices[x].Children.AddLast(y); vertices[y].ParentsCount++; } return(vertices); }
static Dictionary <int, TopoNode> ReadDirectedGraph() { var n = int.Parse(Console.ReadLine()); var m = int.Parse(Console.ReadLine()); var vertices = new Dictionary <int, TopoNode>(); for (var i = 0; i < m; i++) { var edge = Console.ReadLine() .Split(' ') .Select(int.Parse) .ToArray(); var x = edge[0]; var y = edge[1]; if (vertices.ContainsKey(x) == false) { vertices[x] = new TopoNode { ParentsCount = 0, Children = new LinkedList <int>(), }; } if (vertices.ContainsKey(y) == false) { vertices[y] = new TopoNode { ParentsCount = 0, Children = new LinkedList <int>(), }; } vertices[x].Children.AddLast(y); vertices[y].ParentsCount++; } return(vertices); }