class Scratch {
public static int numEdges;
public static int queries;
public static Edge[] paths;
public static Edge[] archs;
public static void main
(String[] args
) { numEdges = 3;
queries = 2;
paths = new Edge[numEdges];
paths[0] = new Edge(1);
paths[1] = new Edge(2);
paths[2] = new Edge(3);
archs = new Edge[queries];
archs[0] = new Edge(10);
archs[1] = new Edge(10);
int pathIndex = 0;
// Reachable artifacts set
for (int i = 0; i < queries; i++) {
System.
out.
println(archs
[i
].
getWeight()); pathIndex = determineViablePaths(archs[i].getWeight());
}
}
// Method to return last index of path that can be traversed
public static int determineViablePaths(int weight) {
for (int i = 0; i < numEdges; i++) {
if (paths[i].getWeight() <= weight)
continue;
else {
return i - 1;
}
}
return numEdges-1;
}
// The edge class
public static class Edge implements Comparable<Edge> {
int weight;
Edge(int weight) {
this.weight = weight;
}
public int getWeight() {
return this.weight;
}
// The Edge comparison method
public int compareTo(Edge other) {
if(this.weight < other.weight)
return 0;
else if (this.weight == other.weight)
return 1;
return -1 ;
}
}
}