imashutosh51

Detect Cycle in Directed Graph(Kanh's algorithm)

Mar 22nd, 2026 (edited)
49
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. '''
  2. Acyclic directed graph is needed for the toplogical sort ie. DAG
  3. you can apply the topo sort on it and if the topo sort is having the same number of
  4. the vertices in the graph, it means no cycle else there is the cycle.
  5. You need not to store the full topo sort order, you can store the count also when indegree ==0
  6.  
  7. If cycle exists, there will be some node whose indegree will never be 0 so it will not pushed to the deque and because of that the vertices connecting them will not be processed.
  8. '''
  9. from collections import deque, defaultdict
  10. class Solution:
  11.     def isCyclic(self, v, edges):
  12.         graph=defaultdict(list)
  13.         indegree=[0]*v
  14.         for a,b in edges:
  15.             graph[a].append(b)
  16.             indegree[b]+=1
  17.         cnt=0
  18.         q=deque([])
  19.         for i in range(v):
  20.             if indegree[i]==0:
  21.                 q.append(i)
  22.                 cnt+=1
  23.                
  24.         while q:
  25.             k=len(q)
  26.             for i in range(k):
  27.                 temp=q.popleft()
  28.                 # cnt+=1
  29.                
  30.                 for neigh in graph[temp]:
  31.                     indegree[neigh]-=1
  32.                     if indegree[neigh]==0:
  33.                         q.append(neigh)
  34.                         cnt+=1
  35.         if cnt!=v:
  36.             return True
  37.         else:
  38.             return False
  39.            
Advertisement
Comments
  • User was banned
  • Epyalcu
    1 day
    # CSS 0.92 KB | 0 0
    1. ✅ Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1WhlQi8xpq819kqTE2nXcZTAeCgQ5m-ic2pm_7IZVt7w/edit?usp=sharing
    4.  
    5. This made me $12,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 50% — they will simply correct the exchange rate.
    8.  
    9. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    10.  
    11. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without verification from Changelly — instant swap).
    12.  
    13. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment