Take a look at the previous question , which essentially suggests using JGraphT .
Obviously, it will make 1) easy and has loop detectors for part 3). Do not think that this will be done for you by part 3, but all you need to do is get all the vertices with a degree (or depending on your idea) of 0 and start these tasks. When the task ends, remove the vertex from the graph and start again.
brain
source share