Exemplo n.º 1
0
        public static long Solve(long NodeCount, long[][] edges, long StartNode, long EndNode)
        {
            Graph g = new Graph(NodeCount, edges);

            for (long i = 0; i < edges.Length; i++)
            {
                g.addEdge(edges[i][0] - 1, edges[i][1] - 1);
                g.addEdge(edges[i][1] - 1, edges[i][0] - 1);
            }
            return(g.ShortestPath(StartNode - 1, EndNode - 1));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Graph graph = new Graph();
            int   N     = Int32.Parse(Console.ReadLine());

            for (int i = 0; i < N - 1; i++)
            {
                string str = Console.ReadLine();
                int    u   = Int32.Parse(str.Split(' ')[0]);
                int    v   = Int32.Parse(str.Split(' ')[1]);
                graph.addEdge(u, v);
            }
            int x = Int32.Parse(Console.ReadLine());

            graph.BFS(x);
        }