Question
Java Programming: Right now Im trying to find a proper way to store the input of the Scanner.in file this problem deals with minimum spanning
Java Programming:
Right now Im trying to find a proper way to store the input of the Scanner.in file this problem deals with minimum spanning trees. The input file looks like this:
// Example Input
3
2 1
1 2 5
3 1
1 2 2
4 4
1 2 2
2 3 3
3 4 1
1 4 4
Okay, so the first line with 1 number indicates the number of cases (in this case its 3 cases). The lines with 2 numbers on it indicate the number of vertices and the number of edges. The lines with 3 numbers indicates the starting node #, the ending node # and the weight of the edge between the two nodes. I'm using Scanner input = new Scanner (System.in); to read the input.in file that matches as shown above. How would I write a java program that prints the sum total weight of the edges in the MST for each case (in this example 1 thru 3.... case 2 can't be solved so just print "No Solution")? I know that the second case isn't solvable too, also print if it can't be solved. I need it to work with the example input that I'm showing above.
My output I needs to look like this (printing out the sum of the edges):
Case 1 : 5
Case 2 : No solution
Case 3: 6
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started