https://leetcode.com/problems/course-schedule/

Time Limit Exceeded

```python
class Solution:
    def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
        #9:34
        allCourse = set()
        chain = dict()

        def tracer(path, key):
            if len(path) > len(allCourse):
                return True
            if key not in allCourse:
                return True
            #print(path, key)
            if key in path:
                return False
            if key not in chain:
                return True
            values = chain[key]
            final = True
            for value in values:
                if tracer(path+[key], value) == False:
                    final = False
            #print(final)
            return final

        def checkIfThereHasLoop():
            for key in allCourse:
                if tracer([], key) == False:
                    return True
            return False

        for a,b in prerequisites:
            allCourse.add(a)
            allCourse.add(b)
            if a not in chain:
                chain[a] = [b]
            else:
                if b not in chain[a]:
                    chain[a].append(b)
            #if b not in chain:
                #chain[b] = []

        #print(allCourse)
        #print(chain)
        if len(allCourse) <= numCourses:
            if checkIfThereHasLoop():
                return False
            else:
                return True
        else:
            return False
        #9:49
        #debug until 10:58
```
