Detect cycle in a directed graph

Problem Link : https://practice.geeksforgeeks.org/problems/detect-cycle-in-a-directed-graph/1/

Can anyone please help me why I am getting TLE in this code…???
https://ide.geeksforgeeks.org/t6ckfYmi2T

maybe because it’s O(nlogn) :/. this should be O(n)