traverse the graph until we get to the end and check the max distance
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=ip), | intent(in) | :: | node_num |
current node |
||
| integer(kind=ip), | intent(in) | :: | idist |
distance to get here |
||
| logical, | intent(in), | dimension(:) | :: | nodes_visited |
recursive subroutine traverse(node_num, idist, nodes_visited) !! traverse the graph until we get to the end and check the max distance integer(ip),intent(in) :: node_num !! current node integer(ip),intent(in) :: idist !! distance to get here logical,dimension(:),intent(in) :: nodes_visited logical,dimension(:),allocatable :: tmp_nodes_visited integer :: i if (nodes_visited(node_num)) return ! already visited this node if (node_num==total_nodes) then ! reached the destination if (idist>max_dist) max_dist = idist ! best so far else ! are their child nodes? if (allocated(nodes(node_num)%inext)) then tmp_nodes_visited = nodes_visited tmp_nodes_visited(node_num) = .true. ! mark this node do i = 1, size(nodes(node_num)%inext) call traverse(nodes(node_num)%inext(i), idist + nodes(node_num)%idist(i), tmp_nodes_visited) end do end if end if end subroutine traverse