Computers and Technology

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();
}
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 09:00, mimithurmond03
Which is the highest level of the hierarchy of needs model? a. humanity b. intrapersonal c. team d. interpersonal
Answers: 1
image
Computers and Technology, 24.06.2019 07:00, erick7123
Why do we mark tlc plates with pencil and not with pen
Answers: 2
image
Computers and Technology, 24.06.2019 10:30, brandon1748
You're programming an infinite loop. what must you include in your code to prevent crashes? in roblox
Answers: 2
image
Computers and Technology, 24.06.2019 20:20, isaiahromero15
Write python code that prompts the user to enter his or her favorite color and assigns the userโ€™s input to a variable named color.
Answers: 1
Do you know the correct answer?
It is the year 3000 and the greedy government has added tolls to all the roads! you are trying to g...

Questions in other subjects:

Konu
Mathematics, 02.04.2021 17:30
Konu
World Languages, 02.04.2021 17:30
Konu
English, 02.04.2021 17:30