[Python3] Tarjan's algo
\n\nclass Solution:\n    def criticalConnections(self, n: int, connections: List[List[int]]) -> List[List[int]]:\n        graph = {} # graph as adjacency list \
\n```\nclass Solution:\n    def criticalConnections(self, n: int, connections: List[List[int]]) -> List[List[int]]:\n        graph = {} # graph as adjacency list \n        for u, v in connections: \n            graph.setdefault(u, []).append(v)\n            graph.setdefault(v, []).append(u)\n        \n        def dfs(x, p, step): \n            """Traverse the graph and collect bridges using Tarjan\'s algo."""\n            disc[x] = low[x] = step\n            for xx in graph.get(x, []): \n                if disc[xx] == inf: \n                    step += 1\n                    dfs(xx, x, step)\n                    low[x] = min(low[x], low[xx])\n                    if low[xx] > disc[x]: ans.append([x, xx]) # bridge\n                elif xx != p: low[x] = min(low[x], disc[xx])\n        \n        ans = []\n        low = [inf]*n\n        disc = [inf]*n\n        \n        dfs(0, -1, 0)\n        return ans \n```
['Python3']