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, 22.06.2019 14:00
What are procedures that keep a data base current
Answers: 1
question
Computers and Technology, 22.06.2019 23:20
How can you tell if someone sent you a text message to your email instead of a email
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
Choose the correct citation for the case which established the "minimum contacts" test for a court's jurisdiction in a case. select one: a. brown v. board of education of topeka, 347 u.s. 483 (1954). b. international shoe co. v. washington, 326 u.s. 310 (1945) c. haynes v. gore, 531 u.s. 98 (2000). d. international shoe co. v. washington, 14 u.s. code 336.
Answers: 1
question
Computers and Technology, 24.06.2019 07:40
What type of multimedia are live news feeds? live news feeds are examples of multimedia.
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, 12.11.2021 18:20
question
Medicine, 12.11.2021 18:30
question
Mathematics, 12.11.2021 18:40
question
Mathematics, 12.11.2021 19:00
Questions on the website: 13722361