calculating path