library("igraph")
M <- as.matrix(read.table("mst_distance_matrix.txt"))
M
##       V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
##  [1,]  0  3  0  0  0  2  0  0  0   0
##  [2,]  3  0 17 16  0  0  0  0  0   0
##  [3,]  0 17  0  8  0  0  0  0 18   0
##  [4,]  0 16  8  0 11  0  0  0  4   0
##  [5,]  0  0  0 11  0  1  6  5 10   0
##  [6,]  2  0  0  0  1  0  7  0  0   0
##  [7,]  0  0  0  0  6  7  0 15  0   0
##  [8,]  0  0  0  0  5  0 15  0 12  13
##  [9,]  0  0 18  4 10  0  0 12  0   9
## [10,]  0  0  0  0  0  0  0 13  9   0
G <- graph_from_adjacency_matrix(M, mode='undirected', weighted = TRUE)
V(G)$color = 2
E(G)$color = 2
plot(G, edge.label=E(G)$weight)

shortest.paths(G, v=1, to=V(G), algorithm="dijkstra")
##    V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
## V1  0  3 20 14  3  2  9  8 13  21
shortest.paths(G, v=V(G), to=V(G), algorithm="dijkstra")
##     V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
## V1   0  3 20 14  3  2  9  8 13  21
## V2   3  0 17 16  6  5 12 11 16  24
## V3  20 17  0  8 19 20 25 24 12  21
## V4  14 16  8  0 11 12 17 16  4  13
## V5   3  6 19 11  0  1  6  5 10  18
## V6   2  5 20 12  1  0  7  6 11  19
## V7   9 12 25 17  6  7  0 11 16  24
## V8   8 11 24 16  5  6 11  0 12  13
## V9  13 16 12  4 10 11 16 12  0   9
## V10 21 24 21 13 18 19 24 13  9   0
shortest_paths(G, 1, to=V(G), output = "both")
## $vpath
## $vpath[[1]]
## + 1/10 vertex, named, from ccae00e:
## [1] V1
## 
## $vpath[[2]]
## + 2/10 vertices, named, from ccae00e:
## [1] V1 V2
## 
## $vpath[[3]]
## + 3/10 vertices, named, from ccae00e:
## [1] V1 V2 V3
## 
## $vpath[[4]]
## + 4/10 vertices, named, from ccae00e:
## [1] V1 V6 V5 V4
## 
## $vpath[[5]]
## + 3/10 vertices, named, from ccae00e:
## [1] V1 V6 V5
## 
## $vpath[[6]]
## + 2/10 vertices, named, from ccae00e:
## [1] V1 V6
## 
## $vpath[[7]]
## + 3/10 vertices, named, from ccae00e:
## [1] V1 V6 V7
## 
## $vpath[[8]]
## + 4/10 vertices, named, from ccae00e:
## [1] V1 V6 V5 V8
## 
## $vpath[[9]]
## + 4/10 vertices, named, from ccae00e:
## [1] V1 V6 V5 V9
## 
## $vpath[[10]]
## + 5/10 vertices, named, from ccae00e:
## [1] V1  V6  V5  V8  V10
## 
## 
## $epath
## $epath[[1]]
## + 0/17 edges from ccae00e (vertex names):
## 
## $epath[[2]]
## + 1/17 edge from ccae00e (vertex names):
## [1] V1--V2
## 
## $epath[[3]]
## + 2/17 edges from ccae00e (vertex names):
## [1] V1--V2 V2--V3
## 
## $epath[[4]]
## + 3/17 edges from ccae00e (vertex names):
## [1] V1--V6 V5--V6 V4--V5
## 
## $epath[[5]]
## + 2/17 edges from ccae00e (vertex names):
## [1] V1--V6 V5--V6
## 
## $epath[[6]]
## + 1/17 edge from ccae00e (vertex names):
## [1] V1--V6
## 
## $epath[[7]]
## + 2/17 edges from ccae00e (vertex names):
## [1] V1--V6 V6--V7
## 
## $epath[[8]]
## + 3/17 edges from ccae00e (vertex names):
## [1] V1--V6 V5--V6 V5--V8
## 
## $epath[[9]]
## + 3/17 edges from ccae00e (vertex names):
## [1] V1--V6 V5--V6 V5--V9
## 
## $epath[[10]]
## + 4/17 edges from ccae00e (vertex names):
## [1] V1--V6  V5--V6  V5--V8  V8--V10
## 
## 
## $predecessors
## NULL
## 
## $inbound_edges
## NULL
sciezka <- shortest_paths(G, 1, to=V(G))$vpath[[10]]
V(G)[sciezka]$color <- 6

sciezka2 <- shortest_paths(G, 1, to=V(G), output = "both")$epath[[10]]
E(G)[sciezka2]$color <- 6

plot(G,edge.label=E(G)$weight)