classSolution: defcriticalConnections(self, n: int, connections: List[List[int]]) -> List[List[int]]: # make adjacency-list of connections adj = defaultdict(list) for u, v in connections: adj[u].append(v) adj[v].append(u)
# define dfs defdfs(u, prev, id, ids, ans): ids[u] = id for v in adj[u]: if v == prev: continue elif ids[v] == -1: ids[u] = min(ids[u], dfs(v, u, id+1, ids, ans)) else: ids[u] = min(ids[u], ids[v])