// function to add an edge to graph

        public void addEdge(int u, int v, int weight)

        {
            AdjListNode node = new AdjListNode(v, weight);

            adj[u].Add(node); // Add v to u's list
        }
        // A function used by shortestPath

        public void topologicalSortUtil(int v, bool[] visited, Stack <int> stack)

        {
            // Mark the current node as visited

            visited[v] = true;
            // Recur for all the vertices adjacent to this vertex
            foreach (var i in adj[v])
            {
                AdjListNode node = i;
                if (!visited[node.vertex])
                {
                    topologicalSortUtil(node.vertex, visited, stack);
                }
            }

            stack.Push(v);
        }