Time Complexity

Can anyone please tell me why the hell time complexity of following code is O(n) Link is given below
: https://leetcode.com/problems/minimum-height-trees/discuss/932797/Python-topological-sort-solution