Calculate transitive closure on the graph once and store the toMap