Problem:
Bridges Find bridges of an undirected graph G(V, E) . A bridge (also known as a cut-edge) is an edge whose deletion increase the number of connected components. Input  |V|  |E|  s 0  t 0  s 1  t 1 : s |E|-1  t |E|-1  , where |V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., |V| -1 respectively.  s i and t i represent source and target nodes of i -th edge (undirected). Output A list of bridges of the graph ordered by name. For each bridge, names of its end-ponints, source and target (source < target), should be printed separated by a space. The sources should be printed ascending order, then the target should also be printed ascending order for the same source. Constraints  1 ≤ |V| ≤ 100,000  0 ≤ |E| ≤ 100,000  The graph is connected  There are no parallel edges  There are no self-loops  Sample Input 1 4 4
0 1
0 2
1 2
2 3 Sample Output 1 2 3 Sample Input 2 5 4
0 1
1 2
2 3
3 4 Sample Output 2 0 1
1 2
2 3
3 4

Solution (Python):
class Graph(): 
    def __init__(self,n,edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0]].append(e[1])
            self.graph[e[1]].append(e[0])
            self.deg[e[0]] += 1
            self.deg[e[1]] += 1

    def lowlink(self): 
        self.ord = [None for _ in range(self.n)]
        self.low = [None for _ in range(self.n)]
        self.group = [None for _ in range(self.n)]
        self.prev = [None for _ in range(self.n)]
        self.tree = [[] for _ in range(self.n)]
        self.sorted = []
        order = 0
        count = 0
        low = [None for _ in range(self.n)]
        for s in range(self.n):
            if self.group[s] is None:
                stack = [(s, None)]
                while stack:
                    node, par = stack.pop()
                    if self.group[node] is None:
                        self.group[node] = count
                        self.ord[node] = order
                        self.sorted.append(node)
                        order += 1
                        if par is not None:
                            self.prev[node] = par
                            self.tree[par].append(node)
                        for adj in self.graph[node]:
                            if self.group[adj] is None:
                                stack.append((adj, node))
                count += 1
        for node in self.sorted[::-1]:
            self.low[node] = self.ord[node]
            for adj in self.graph[node]:
                if self.prev[adj]  == node:
                    self.low[node] = min(self.low[node], self.low[adj])
                elif self.prev[node] == adj:
                    continue
                else:
                    self.low[node] = min(self.low[node], self.ord[adj])

    def articulation(self):
        res = []
        for node in range(self.n):
            if self.prev[node] is None and len(self.tree[node]) > 1:
                res.append(node)
            if self.prev[node] is not None:
                for adj in self.tree[node]:
                    if self.ord[node] <= self.low[adj]:
                        res.append(node)
                        break
        return res

    def bridge(self):
        res = []
        for node in range(self.n):
            for adj in self.tree[node]:
                if self.ord[node] < self.low[adj]:
                    res.append((node, adj))
        return res


import sys
input = sys.stdin.readline

N, M = map(int, input().split())
E = [tuple(map(int, input().split())) for _ in range(M)]

g = Graph(N, E)
g.lowlink()
res = g.bridge()
res = list(map(lambda x: (min(x), max(x)), res))
res.sort()
if res:
    print('\n'.join(map(lambda x: ' '.join(map(str, x)), res)))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 8)


def lowLink(N: int, Adj: list):
	articulation = []
	bridge = []
	order = [None] * N
	lowest = [1 << 100] * N

	def _dfs(cur, pre, k):
		order[cur] = lowest[cur] = k
		is_articulation = False
		cnt = 0
		for nxt in Adj[cur]:
			if order[nxt] is None:
				cnt += 1
				_dfs(nxt, cur, k + 1)
				if lowest[cur] > lowest[nxt]:
					lowest[cur] = lowest[nxt]
				is_articulation |= pre >= 0 and lowest[nxt] >= order[cur]
				if order[cur] < lowest[nxt]:
					if cur < nxt:
						bridge.append((cur, nxt))
					else:
						bridge.append((nxt, cur))
			elif nxt != pre and lowest[cur] > order[nxt]:
				lowest[cur] = order[nxt]
		is_articulation |= pre < 0 and cnt > 1
		if is_articulation:
			articulation.append(cur)

	_dfs(0, -1, 0)
	return articulation, bridge


def main():
	n, m, *L = map(int, open(0).read().split())
	adj = [[] for _ in range(n)]
	for s, t in zip(*[iter(L)] * 2):
		adj[s] += t,
		adj[t] += s,
	_, bridge = lowLink(n, adj)
	for x, y in sorted(bridge):
		print(x, y)


if __name__ == '__main__':
	main()

Solution (Python):
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def low_link(nodes):
    N = len(nodes)
    visited = [False] * N
    prenum = [0] * N
    parent = [0] * N
    lowest = [0] * N
    bridges = []
    timer = 1

    def rec(cur, prev, timer):
        
        prenum[cur] = lowest[cur] = timer
        timer += 1
        visited[cur] = True
        for nxt in nodes[cur]:
            if not visited[nxt]:
                
                parent[nxt] = cur
                timer = rec(nxt, cur, timer)
                
                lowest[cur] = min(lowest[cur], lowest[nxt])
                
                if lowest[nxt] == prenum[nxt]:
                    
                    bridges.append((min(cur, nxt), max(cur, nxt)))
            elif nxt != prev:
                
                lowest[cur] = min(lowest[cur], prenum[nxt])
        return timer
    
    for i in range(N):
        if not visited[i]:
            timer = rec(i, -1, timer)

    
    aps = set()
    
    np = 0
    for i in range(1, N):
        p = parent[i]
        if p == 0:
            np += 1
        
        elif prenum[p] <= lowest[i]:
            aps.add(p)
    
    if np > 1:
        aps.add(0)

    return aps, bridges

N, M = MAP()
nodes = [[] for i in range(N)]
for i in range(M):
    u, v = MAP()
    nodes[u].append(v)
    nodes[v].append(u)

aps, bridges = low_link(nodes)

bridges = sorted(bridges)
for x in bridges:
    print(*x)

Solution (Python):

import sys
class LowLinks:
    def __init__(self, edges, v, root=0):
        self.edges = edges
        self.root = root
        self.ord = [None] * v
        self.low = [None] * v
        self.cnt = 0
        self.bridges = []
        self.articulations = set()
        self.par = [None] * v

    def build(self):
        self.search(self.root)

    def search(self, x):
        self.ord[x] = self.cnt
        self.low[x] = self.cnt
        self.cnt += 1
        dim = 0
        for to in self.edges[x]:
            if to == self.par[x]:continue
            if self.ord[to] != None:
                self.low[x] = min(self.low[x], self.ord[to])
            else:
                self.par[to] = x
                self.search(to)
                dim += 1
                self.low[x] = min(self.low[x], self.low[to])

                if x != self.root and self.ord[x] <= self.low[to]:
                    self.articulations.add(x)

            if x == self.root and dim > 1:
                self.articulations.add(x)

            if self.ord[x] < self.low[to]:
                self.bridges.append((x, to))

sys.setrecursionlimit(1000000)
n,m=map(int,input().split())
edges=[[] for _ in range(n)]
for _ in range(m):
    s, t = map(int, input().split())
    edges[s].append(t)
    edges[t].append(s)

l=LowLinks(edges,n)
l.build()
ans=[]
for i,j in l.bridges:
    if i>j:
        ans.append((j,i))
    else:
        ans.append((i,j))
ans.sort()
for i,j in ans:
    print(i,j)

Solution (Python):
from typing import List
from typing import Tuple
from functools import cmp_to_key
import sys

sys.setrecursionlimit(100000)

def find_bridges(adj, n) -> List[Tuple[int, int]]:
    mark = [False for _ in range(n)] 
    edges = []
    low_link = [None for _ in range(n)]
    id = [0]

    for v in range(n):
        if not mark[v]:
            ____find_bridges(v, -1, adj, id, low_link, mark, edges)
    return edges


def ____find_bridges(node: int, parent: int, adj, id: List[int], low_link: List[int], mark: List[bool], edges):

    mark[node] = True
    low_link[node] = id[0]
    node_id = id[0]

    for v in adj[node]:
        if v == parent: continue
        if not mark[v]:
            id[0] += 1
            ____find_bridges(v, node, adj, id, low_link, mark, edges)
        low_link[node] = min(low_link[node], low_link[v])
        if low_link[v] > node_id:
            edges.append([node, v])

def read() -> Tuple[List, int]:

    info = [int(e) for e in input().split()]
    n, e = info[0], info[1]
    adj = [[] for _ in range(n)]
    for _ in range(e):
        edge = [int(i) for i in input().split()]
        adj[edge[0]].append(edge[1])
        adj[edge[1]].append(edge[0])
    
    return adj, n

def custom_cmp(edgeA, edgeB):
    if edgeA[0] == edgeB[0]:
        return edgeA[1] - edgeB[1]
    
    return edgeA[0] - edgeB[0]

def process_output(edges: List[List[int]]) -> List[List[int]]:
    for edge in edges:
        edge.sort()
    n_edges = list(sorted(edges, key=cmp_to_key(custom_cmp)))
    return n_edges

def show(edges):
    for edge in edges:
        print('%d %d' % (edge[0], edge[1]))

adj, n = read()
edges = find_bridges(adj, n)
n_edges = process_output(edges)
show(n_edges)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

class LowLink:
    def __init__(self, v):
        self.size = len(v)
        self.v = v
        self.pre = [None]*self.size
        self.low = [None]*self.size
        self.articulation = []
        self.bridge = []
        for x in range(self.size):
            if self.pre[x] is None:
                self.cnt = 0
                self.dfs(x,None)

    def dfs(self, x, par):
        self.pre[x] = self.low[x] = self.cnt
        self.cnt += 1
        is_articulation = False
        n = 0
        for y in self.v[x]:
            if self.pre[y] is None:
                n += 1
                lowy = self.dfs(y, x)
                if lowy < self.low[x]:
                    self.low[x] = lowy
                if self.pre[x] <= lowy:
                    if self.pre[x]:
                        is_articulation = True
                    if self.pre[x] < lowy:
                        self.bridge.append((x,y))
            else:
                if par != y and self.pre[y] < self.low[x]:
                    self.low[x] = self.pre[y]

        if par is None and n > 1:
            is_articulation = True

        if is_articulation:
            self.articulation.append(x)

        return self.low[x]


def solve():
    n,m = LI()
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        v[a].append(b)
        v[b].append(a)
    lowlink = LowLink(v)
    bridge = lowlink.bridge
    for i in range(len(bridge)):
        l,r = bridge[i]
        if r < l:
            bridge[i] = (r,l)
    for i in sorted(bridge):
        print(*i)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
def bridges(E, s):
    N = len(E)
    preorder = [-1] * N 
    lowpt = [N] * N 
    bridge = []
    stack = [(s, -1, 0)] 
    pre_num = 0 
    while stack:
        v, p, st = stack.pop()
        if st == 0 and preorder[v] < 0: 
            preorder[v] = pre_num
            lowpt[v] = pre_num
            pre_num += 1
            n_children = 0
            for u in E[v]:
                if preorder[u] >= 0:
                    if u != p: 
                        lowpt[v] = min(lowpt[v], preorder[u])
                    continue
                if n_children == 0:
                    stack += [(v, p, 2), (u, v, 0)]
                    n_children += 1
                else:
                    stack += [(v, p, 1), (u, v, 0)]
                    n_children += 1
            if n_children == 0: 
                lowpt[p] = min(lowpt[p], lowpt[v])
                if lowpt[v] > preorder[p]: bridge.append((v, p) if v < p else (p, v))
        elif st == 0 and preorder[v] >= 0: 
            continue
        elif st == 1: 
            continue
        else: 
            if p != -1:
                lowpt[p] = min(lowpt[p], lowpt[v])
                if lowpt[v] > preorder[p]: bridge.append((v, p) if v < p else (p, v))
    return bridge

N, M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    s, t = map(int, input().split())
    E[s].append(t); E[t].append(s)
br = sorted(bridges(E, 0))
for s, t in br:
    print(s, t)

Solution (Python):



import sys

sys.setrecursionlimit(100000)

V, E = list(map(int, input().split()))
Edge = [list(map(int, input().split())) for _ in range(0, E)]

ord = [0 for _ in range(0, V)]
low = [0 for _ in range(0, V)]
used = [False for _ in range(0, V)]
bridge = []

G = [ [] for _ in range(0, V)]
for s, t in Edge:
    G[s] += [t]
    G[t] += [s]


def dfs(s, p, k):
    global articulation
    used[s] = True
    ord[s] = k
    low[s] = ord[s]
    k += 1
    c = 0
    
    
    for t in G[s]:
        
        if used[t] == False:
            c += 1
            dfs(t, s, k)
            
            low[s] = min(low[s], low[t])
        
        elif t != p:
            
            low[s] = min(low[s], ord[t])

for s in range(0, V): 
    if used[s] == False:
        dfs(s, -1, 0)

for s, t in Edge:
    if ord[s] < low[t] or ord[t] < low[s]:
        if s < t:
            bridge += [(s, t)]
        else:
            bridge += [(t, s)]

bridge.sort()
for s, t in bridge:
    print(s, t)

Solution (Python):
import sys
from typing import List, Set


sys.setrecursionlimit(200000)


def dfs(cur : int, prev: int) -> None:
    global prenum, parent, lowest, counter, bridges
    prenum[cur] = lowest[cur] = counter
    counter += 1
    for edge in edges[cur]:
        if prenum[edge] != sys.maxsize:
            if edge != prev:
                lowest[cur] = min(lowest[cur], prenum[edge])
            continue
        parent[edge] = cur
        dfs(edge, cur)
        lowest[cur] = min(lowest[cur], lowest[edge])
    if prenum[cur] == lowest[cur]:
        bridges.add((cur, prev) if cur < prev else (prev, cur))


if __name__ == "__main__":
    V, E = map(int, input().split())
    edges: List[Set[int]] = [set() for _ in range(V)]

    for _ in range(E):
        s, t = map(int, input().split())
        edges[s].add(t)
        edges[t].add(s)

    prenum = [sys.maxsize] * V
    parent = [sys.maxsize] * V
    lowest = [sys.maxsize] * V
    counter = 0
    bridges = set()  

    dfs(0, -1)
    for bridge in sorted(bridges)[1:]:
        print(*bridge)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
write = sys.stdout.write

N, M = map(int, readline().split())

G = [[] for i in range(N)]
for i in range(M):
    u, v = map(int, readline().split())
    G[u].append(v)
    G[v].append(u)


def construct(G, N):
    P = [0]*N
    G0 = [[] for i in range(N)]
    V = []
    lb = [0]*N
    def dfs(v, p):
        P[v] = p
        V.append(v)
        lb[v] = len(V)
        for w in G[v]:
            if w == p:
                continue
            if lb[w]:
                if lb[v] < lb[w]:
                    
                    G0[v].append(w)
                continue
            
            dfs(w, v)
    dfs(0, -1)

    used = [0]*N
    first = 1
    B = []
    used[0] = 1
    ap = [0]*N
    for u in V:
        if not used[u]:
            
            p = P[u]
            B.append((u, p) if u < p else (p, u))
            if len(G[u]) > 1:
                ap[u] = 1
            if len(G[p]) > 1:
                ap[p] = 1
        cycle = 0
        for v in G0[u]:
            w = v
            while w != u and not used[w]:
                used[w] = 1
                w = P[w]
            if w == u:
                cycle = 1
        if cycle:
            if not first:
                ap[u] = 1
            first = 0
    
    A = [v for v in range(N) if ap[v]]

    return B, A

B, A = construct(G, N)

B.sort()
for u, v in B:
    write("%d %d\n" % (u, v))

Solution (Python):
import sys
readline = sys.stdin.readline


sys.setrecursionlimit(10**7)
class LowLinks:
    def __init__(self, edges, edges_num:int):
        """edges[u]: all vertexes connected with vertex 'u'
        edges_num: number of edges of graph
        the root of DFS-tree is vertex 0
        """
        self.edges = edges
        self.V = len(edges)
        self.order = [-1]*V
        self.low = [float('inf')]*V
        self.bridges = []
        
        self.articulations = []
        if len(edges[0]) > 1 and edges_num == self.V-1:
            self.articulations.append(0)
        self.k = 0

    def build(self):
        self.dfs(0, 0)

    def get_bridges(self)->tuple:
        return self.bridges

    def get_articulations(self)->tuple:
        return self.articulations

    def dfs(self, v:int, prev:int):
        self.order[v] = self.k
        self.low[v] = self.k
        self.k += 1
        is_articulation = False
        for to in self.edges[v]:
            if self.order[to] < 0: 
                self.dfs(to, v)
                self.low[v] = min(self.low[v], self.low[to])
                if self.order[v] < self.low[to]:
                    self.bridges.append((v, to) if v < to else (to, v))
                is_articulation |= self.order[v] <= self.low[to]
            elif to != prev: 
                self.low[v] = min(self.low[v], self.order[to])
        if v>0 and is_articulation:
            self.articulations.append(v)

if __name__ == "__main__":
    V,E = map(int, readline().split())
    edges = [[] for _ in range(V)]
    for _ in range(E):
        s,t = map(int, readline().split())
        edges[s].append(t)
        edges[t].append(s)
    lowlinks = LowLinks(edges, E)
    lowlinks.build()
    bridges = lowlinks.get_bridges()
    bridges.sort()
    if bridges:
        for s,t in bridges:
            print(s, t)

Solution (Python):
import sys
sys.setrecursionlimit(1000000)

def input(f):
    global v, e
    global s, t
    
    v, e = map(int, f.readline().split())
    s = [-1 for _ in range(e)]
    t = [-1 for _ in range(e)]
    for i in range(e):
        s[i], t[i] = map(int, f.readline().split())

def solve():
    g = [[] for _ in range(v)]
    for i in range(e):
        g[s[i]].append(t[i])
        g[t[i]].append(s[i])
    
    used = [False for _ in range(v)]
    ord = [-1 for _ in range(v)]
    low = [10**6 for _ in range(v)]
    res = []
    
    def rec(cur, prev, d):
        if used[cur]:
            return
        used[cur] = True
        ord[cur] = d
        low[cur] = ord[cur]
        
        cnt = 0
        for nxt in g[cur]:
            if not used[nxt]:
                cnt += 1
                rec(nxt, cur, d+1)
                low[cur] = min(low[cur], low[nxt])
                if prev >= 0 and ord[cur] < low[nxt]:
                    res.append((min(cur, nxt), max(cur, nxt)))
            elif nxt != prev:
                low[cur] = min(low[cur], ord[nxt])
        
        if prev == -1 and (cnt >= 2 or len(g[cur]) == 1):
            for nxt in g[cur]:
                res.append((min(cur, nxt), max(cur, nxt)))
    
    rec(0, -1, 0)
    
    for src, dst in sorted(res):
        print('{} {}'.format(src, dst))

with open('/dev/stdin') as f:
    input(f)
    solve()

Solution (Python):
import sys

sys.setrecursionlimit(int(1e6))

n, m = map(int, input().split())

edges = {}

for i in range(m):
    s, t = map(int, input().split())
    if s not in edges:
        edges[s] = set()
    if t not in edges:
        edges[t] = set()
    edges[s].add(t)
    edges[t].add(s)

order = [0] * n
lowlink = [0] * n
visited = set()
bridges = set()


def dfs(v, p, i):
    visited.add(v)

    i += 1
    lowlink[v] = order[v] = i

    if v not in edges:
        return

    for t in edges[v]:
        if t not in visited:
            dfs(t, v, i)
            lowlink[v] = min(lowlink[v], lowlink[t])
            if lowlink[t] == order[t]:
                bridges.add((min(v, t), max(v, t)))
        elif t != p:
            lowlink[v] = min(lowlink[v], lowlink[t])


k = 0
for i in range(n):
    if i not in visited:
        dfs(i, -1, k)

for s, t in sorted(bridges):
    print(s, t)

Solution (Python):
import sys

class LowLinks:
    def __init__(self, edges, v, root=0):
        self.edges = edges
        self.root = root
        self.ord = [None] * v
        self.low = [None] * v
        self.cnt = 0
        self.bridges = []
        self.articulations = set()
        self.par = [None] * v

    def build(self):
        self.search(self.root)

    def search(self, x):
        self.ord[x] = self.cnt
        self.low[x] = self.cnt
        self.cnt += 1
        dim = 0
        for to in self.edges[x]:
            if to == self.par[x]:continue
            if self.ord[to] != None:
                self.low[x] = min(self.low[x], self.ord[to])
            else:
                self.par[to] = x
                self.search(to)
                dim += 1
                self.low[x] = min(self.low[x], self.low[to])

                if x != self.root and self.ord[x] <= self.low[to]:
                    self.articulations.add(x)

            if x == self.root and dim > 1:
                self.articulations.add(x)

            if self.ord[x] < self.low[to]:
                self.bridges.append((x, to))


sys.setrecursionlimit(1000000)
v, e = map(int, input().split())
edges = [[] for _ in range(v)]
for _ in range(e):
    s, t = map(int, input().split())
    edges[s].append(t)
    edges[t].append(s)

lowlinks = LowLinks(edges, v)
lowlinks.build()
if lowlinks.bridges:
    bridges = sorted(lowlinks.bridges, key=lambda x: (min(x), max(x)))
    for bridge in bridges:
        print(min(bridge), max(bridge))

Solution (Python):



class Edge:
    __slots__ = ('v', 'w')

    def __init__(self, v, w):
        self.v = v
        self.w = w

    def either(self):
        return self.v

    def other(self, v):
        if v == self.v:
            return self.w
        else:
            return self.v


class Graph:
    def __init__(self, v):
        self.v = v
        self._edges = [[] for _ in range(v)]

    def add(self, e):
        self._edges[e.v].append(e)
        self._edges[e.w].append(e)

    def adj(self, v):
        return self._edges[v]

    def edges(self):
        for es in self._edges:
            for e in es:
                yield e


def bridges(graph):
    def visit(v, e):
        nonlocal n
        w = e.other(v)
        if not visited[w]:
            parent[w] = v
            n += 1
            visited[w] = n
            low[w] = n
            return True
        elif w != parent[v]:
            low[v] = min(low[v], visited[w])
            return False

    def leave(p, e):
        c = e.other(p)
        if p == parent[c] and low[c] > visited[p]:
            es.append(e)
        low[p] = min(low[p], low[c])
        return False

    visited = [0] * graph.v
    low = [0] * graph.v
    parent = [-1] * graph.v
    es = []

    s = 0
    n = 1
    visited[s] = n
    low[s] = n
    stack = [(s, e, visit) for e in graph.adj(s)]

    while stack:
        v, e, func = stack.pop()
        
        if func(v, e):
            stack.append((v, e, leave))
            w = e.other(v)
            for ne in graph.adj(w):
                stack.append((w, ne, visit))

    return es


def run():
    v, e = [int(i) for i in input().split()]
    g = Graph(v)

    for _ in range(e):
        s, t = [int(i) for i in input().split()]
        g.add(Edge(s, t))

    edges = [(e.v, e.w) if e.v < e.w else (e.w, e.v)
             for e in bridges(g)]

    for v, w in sorted(edges):
        print(v, w)


if __name__ == '__main__':
    run()