Check for path in a directed graph