如果我有总节点数和它们之间的距离,如何创建路径?

我想生成一个图表。 我有3个输入。 节点总数和它们之间的距离。

例如,

Total no of nodes J = 6, no of path can be created from them R = 8 input3 = {1#2#8, 1#4#7, 1#5#12, 2#3#4, 2#4#2, 3#6#6, 4#6#8, 5#6#10}. 

我有这个信息。 第一个数字代表起始节点,第二个数字代表结束节点,第三个数字代表它们之间的距离,即第1和第2个节点之间的距离是8,第1和第4个节点之间的距离是7。

现在我想从它们创建路径。 我需要像这样的输出:

 first path can be 1->2->3-> 6 and total cost for that is 18 second path can be 1->2->4->6 and total cost for that is 18 third path can be 1->4->6 and total cost for that is 15 fourth path can be 1->5->6 and total cost for that is 22 

如何在Java中实现这种类型的程序?