Create shortest distance between two nodes.java