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, 23.06.2019 06:40
What are the three uses of a screw?
Answers: 2
question
Computers and Technology, 23.06.2019 23:30
A. in packet tracer, only the server-pt device can act as a server. desktop or laptop pcs cannot act as a server. based on your studies so far, explain the client-server model.
Answers: 2
question
Computers and Technology, 24.06.2019 02:10
Which sentences describe the things you need to ensure while creating a sketch and a drawing? while an artistic or creative drawing is a creative expression, a technical drawing is an informative expression. you need to create accurate and neat drawings to convey accurate information. a technical drawing clearly conveys its meaning or information, and does not leave room for interpretation maintain a good speed while creating drawings
Answers: 1
question
Computers and Technology, 24.06.2019 02:20
Peter is thinking of a number which isless than 50. the number has 9 factors.when he adds 4 to the number, itbecomes a multiple of 5. what is thenumber he is thinking of ?
Answers: 1
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
English, 07.05.2021 05:20
Questions on the website: 13722367