```
def canFinish(self, numCourses, prerequisites):
forbid = {} # maintaining a predecessor table
for x,y in prerequisites:
if y in forbid:
forbid[y].append(x)
else:
forbid[y] = [x]
if x in forbid:
forbid[y].extend([s for s in forbid[x] if s not in forbid[y]]) # only need to add the predecessor's predecessor
if y in forbid[x]: return False # conflict
return True
```