void () { myNonTreeEdges = new MultiMap<>(); mySortedNodes = new ArrayList<>(); myNextNodes = new HashMap<>(); Object2IntMap<Node> distances = new Object2IntOpenHashMap<>(); Deque<Node> nodes = new ArrayDeque<>(); nodes.addLast(myFinish); distances.put(myFinish, 0); while (!nodes.isEmpty()) { myProgressIndicator.checkCanceled(); Node node = nodes.removeFirst(); mySortedNodes.add(node); int d = distances.getInt(node) + 1; Iterator<Node> iterator = myGraph.getIn(node); while (iterator.hasNext()) { Node prev = iterator.next(); if (distances.containsKey(prev)) { int dPrev = distances.getInt(prev); myNonTreeEdges.putValue(prev, new GraphEdge<>(prev, node, d - dPrev)); continue; } distances.put(prev, d); myNextNodes.put(prev, node); nodes.addLast(prev); } } }