-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
58 lines (49 loc) · 1.55 KB
/
Test.java
File metadata and controls
58 lines (49 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*IMPORTANT NOTE:
* DO NOT
* MAKE ANY CHANGES
* TO THIS CLASS.*/
public class Test{
public static void main(String[] args) throws FileNotFoundException {
int NumberOfVertices=0;
int NumberOfEdges=0;
int NumberOfOrigin=0;
ArrayList<String> vert=new ArrayList();
int[][] edges=null;
/*In Eclipse and other IDE the input file needs to be taken from src/input.txt path
* as all the java files are part of src directory by default*/
File file = new File("input.txt");
if (!file.isFile())
file = new File("src/input.txt");
Scanner sc = new Scanner(file);
NumberOfVertices=sc.nextInt();
NumberOfEdges=sc.nextInt();
NumberOfOrigin=sc.nextInt();
for(int i=0;i<NumberOfVertices;i++)
{
vert.add(sc.next());
}
edges=new int[NumberOfEdges][3];
for(int i=0;i<NumberOfEdges;i++)
{
edges[i][0]=sc.nextInt();
edges[i][1]=sc.nextInt();
edges[i][2]=sc.nextInt();
}
//Generate graph with vertices and edges
Graph<String> graph1 = new Graph();
List<List<Graph<String>.Edge>> adjList=graph1.createWeightedGraph(vert, edges);
//build tree for shortest path from Chicago to every node
for(int i=0;i<NumberOfOrigin;i++)
{
Graph<String>.Tree tree1 = graph1.getShortestPath(sc.next(),vert,adjList);
//print shortest path to each node from Chicago
tree1.printAllPaths(vert);
System.out.println();
}
}
}