subject

It is the year 3000 and the greedy government has added tolls to all the roads! you are trying to get to gsu to take professor kumar's exam, but don't want to spend a lot of money on these silly tolls. you are leaving quite early in the morning, so time is not a concern.
there are up to 8 possible tolls, but you don't need to visit all 8. you just need to get to toll h as it is the closest one to gsu. you will always start at toll a.
when reading the input, the first line will be the number of edges. each edge would come on its own line, in the format of start end toll.
expected output is the minimum number of dollars required for the trip.
i have written the input/output writing code for you. you can rewrite it if you'd like, but you do not need to.
your findcheapestpath function is given a list> as input. this could look like
list[0] = ["a", "b", "3"];
list[1] = ["a", "c", "4"];
list[2] = ["c", "h", "2"];
list[3] = ["b", "h", "9"];
a good step one would be to use this input list to create some nodes and edges, and then write some kind of search to find your end node! good luck!
input format
4
a b 3
a c 4
c h 2
b h 9

constraints
you may use use imports from java. util.*. you can assume there are no infinite loops, and that, the graph is finite (at most 8 tolls). there will also always be a path from a to h. if you are unable to write the code to find the smallest path, consider just finding a path that has weight less than 10. this will give you a large majority of the points (most of the test hint: all of the repl. its have been left up!

output format
6
sample input 0
4
a b 3
a c 4
c h 2
b h 9
sample output 0
6
explanation 0
the graph is of a, b, c, h. a points to b and c, with weights 3 and 4 respectively. c and b point to h, with weights 2 and 9 respectively. shortest path from a-h would be a-c (4) + c-h(2) = 6.
complete in java:
starter code:
import java. io.*;
import java. math.*;
import java. security.*;
import java. text.*;
import java. util.*;
import java. util. concurrent.*;
import java. util. function.*;
import java. util. regex.*;
import java. util. stream.*;
import static java. util. stream. collectors. joining;
import static java. util. stream. collectors. tolist;
class result {
/*
* complete the 'findcheapestpath' function below.
*
* the function is expected to return an integer.
* the function accepts 2d_string_array edges as parameter.
*/
public static int findcheapestpath(list> edges) {
// write your code here
hashmap map = new hashmap< > ();
for (list edge: edges) {
node a = map. get(edge. get(0)); // start node;
if (a == null) {
a = new node(edge. get(0));
map. put(edge. get(0), a);
}
node b = map. get(edge. get(1)); // end node;
if (b == null) {
b = new node(edge. get(1));
map. put(edge. get(1), b);
}
// add edge
a. add(new nodeedge(b, integer. parseint(edge. get(;
}

// todo: find path from a to h

return dfs(map. get("a"), map. get("h"));

}

// bfs is fine too!
public static int dfs(node a, node b) {
//return true only if you get a==b and weightsofar< =10
}

}
class node {
string value;
arraylist edges;
public node(string value) {
edges = new arraylist< > ();
this. value = value;
}

public void add (nodeedge edge) {
edges. add(edge);
}
}

class nodeedge{
node end;
int weight;
public nodeedge(node end, int weight) {
this. end = end;
this. weight = weight;
}
}

}

public class solution {
public static void main(string[] args) throws ioexception {
bufferedreader bufferedreader = new bufferedreader(new inputstreamreader(system. in));
bufferedwriter bufferedwriter = new bufferedwriter(new filewriter(system. getenv("output_path";

int n = integer. parseint(bufferedreader.;

list> arr = new arraylist< > ();

intstream. range(0, n).foreach(i -> {
try {
arr. add(
stream. of(bufferedreader.("\\s+$", "").split(" "))
.collect(
);
} catch (ioexception ex) {
throw new runtimeexception(ex);
}
});

int result = result. findcheapestpath(arr);

bufferedwriter. write(string. valueof(result));
bufferedwriter. newline();

bufferedreader. close();
bufferedwriter. close();
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 06:50
What are the things you are considering before uploading photos on social media?
Answers: 1
question
Computers and Technology, 24.06.2019 21:30
Jenny wants to create an animated short video to add to her website. which software will she use to create this animated video?
Answers: 1
question
Computers and Technology, 24.06.2019 22:30
To include a watermark or page border on a word document, you will first need to navigate to the tab. file home insert design
Answers: 1
question
Computers and Technology, 25.06.2019 03:30
Which task should happen during the planning stage of a project
Answers: 2
You know the right answer?
It is the year 3000 and the greedy government has added tolls to all the roads! you are trying to g...
Questions
question
Mathematics, 09.01.2020 23:31
question
Chemistry, 09.01.2020 23:31
question
Mathematics, 09.01.2020 23:31
Questions on the website: 13722360