fix count vertices issue
added topological sort