imashutosh51

Detect cycle in undirected graph

Mar 22nd, 2026 (edited)
57
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. """
  2. Intuition:
  3.  
  4. We are exploring an undirected graph using DFS to check if a cycle exists. Because the graph is undirected, every edge works in both directions so while pushing edge(a,b) in the adjacent direction , push a->b and b->a both.
  5. for eg we have only edge ie (0,1) so adjacency matrix would be {0->1, 1->0}.
  6.  
  7. we will go dfs and the moment we will see any neighbor is having already visited, we will just return the false but there is a problem and the problem when you will go from 0 to 1 then the neighbor of 1 would 0 too which is already visited, so you can't return the False there, so just keep track of the parent and return Cycle only if the neighbor is True and not parent.
  8. """
  9.  
  10.  
  11. from collections import defaultdict
  12. def fun(i,parent,graph,visited):
  13.     visited[i]=True
  14.     for k in graph[i]:
  15.         if visited[k]==True and k!=parent:
  16.             return True
  17.         elif visited[k]==False and fun(k,i,graph,visited):
  18.             return True
  19.     return False
  20.  
  21. class Solution:
  22.     def isCycle(self, v, edges):
  23.         visited=[False]*v
  24.         graph=defaultdict(list)
  25.         for a,b in edges:
  26.             graph[a].append(b)
  27.             graph[b].append(a)
  28.         for i in range(v):
  29.             if visited[i]==False:
  30.                 if fun(i,-1,graph,visited):
  31.                     return True
  32.         return False
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