Problem:
 Score : 300 points    Problem Statement You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i -th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i .  An edge whose removal disconnects the graph is called a bridge . Find the number of the edges that are bridges among the M edges.      Notes  A self-loop is an edge i such that a_i=b_i  (1 \leq i \leq M) .  Double edges are a pair of edges i,j such that a_i=a_j and b_i=b_j  (1 \leq i<j \leq M) .  An undirected graph is said to be connected when there exists a path between every pair of vertices.       Constraints  2 \leq N \leq 50  N-1 \leq M \leq min(N(N−1)⁄2,50)  1 \leq a_i<b_i \leq N  The given graph does not contain self-loops and double edges.  The given graph is connected.         Input Input is given from Standard Input in the following format:  N  M  a_1  b_1  a_2  b_2  :  a_M  b_M       Output Print the number of the edges that are bridges among the M edges.        Sample Input 1 7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7      Sample Output 1 4  The figure below shows the given graph:     The edges shown in red are bridges. There are four of them.       Sample Input 2 3 3
1 2
1 3
2 3      Sample Output 2 0  It is possible that there is no bridge.       Sample Input 3 6 5
1 2
2 3
3 4
4 5
5 6      Sample Output 3 5  It is possible that every edge is a bridge.

Solution (Python):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = map(int,input().split())
edges = []
for i in range(M):
    x = list(map(int,input().split()))
    edges.append(x)
ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if j != i:
            uf.union(edges[j][0]-1,edges[j][1]-1)
        if j == M-1 and uf.group_count() != 1:
            ans += 1
print(ans)

Solution (Python):
def main():
    N, M = map(int, input().split())
    edges = []
    m = [[0 for _ in range(N)] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        edges.append([a-1, b-1])
        m[a-1][b-1] = 1
        m[b-1][a-1] = 1

    ans = 0
    for e in edges:
        m[e[0]][e[1]] = 0
        m[e[1]][e[0]] = 0
        global visited
        visited = [0] * N
        dfs(0, m)
        if sum(visited) != N:
            ans += 1
        m[e[0]][e[1]] = 1
        m[e[1]][e[0]] = 1
    print(ans)


def dfs(node, m):
    global visited
    visited[node] = 1
    for i, edge_flag in enumerate(m[node]):
        if edge_flag == 1 and visited[i] != 1:
            dfs(i, m)


if __name__ == '__main__':
    main()

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

N,M = map(int,readline().split())
bridges = [None] * M
G = [[] for i in range(N)]

for i in range(M):
  a,b = map(int,readline().split())
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)
  bridges[i] = (a - 1, b - 1)
  
from collections import deque

ans = 0
for i in range(M):
  q = deque([])
  q.append(0)
  seen = set()
  while q:
    v = q.popleft()
    if v in seen:
      continue
    seen.add(v)
    for child in G[v]:
      if (v, child) == bridges[i] or (child, v) == bridges[i]:
        continue
      q.append(child)
  if len(seen) != N:
    ans += 1
    
print(ans)

Solution (Python):
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))
    
class UnionFind():
    
    
    
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n
        self.group = n
    
    
    def root(self, x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]
    
    
    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x==y:
            return
        
        if self.parents[x]>self.parents[y]:
            x,y = y,x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
        self.group -= 1
    
    
    def same(self, x, y):
        return self.root(x)==self.root(y)

    
    def size(self, x):
        return -self.parents[self.root(x)]



N,M=mint()
node=[]
for _ in range(M):
    node.append(lint())
ans=0
for i in range(M):
    t=UnionFind(N)
    for j in range(M):
        if j!=i:
            t.union(node[j][0]-1,node[j][1]-1)
    if t.size(0)<N:
        ans+=1
print(ans)

Solution (Python):
class UnionFind():
  def __init__(self,n):
    self.n=n
    self.parents =[-1]*n

  def find(self, x):
    if self.parents[x]<0:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x=self.find(x)
    y=self.find(y)
    if x==y:
      return
    if self.parents[x]>self.parents[y]:
      x,y=y,x
    self.parents[x]+=self.parents[y]
    self.parents[y]=x
    
  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x)==self.find(y)

  def members(self, x):
    root=self.find(x)
    return list(i for i in range(self.n) if self.find(i) == root)

  def roots(self):
    return list(i for i, x in enumerate(self.parents) if x < 0)

  def group_count(self):
    return len(self.roots)

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

adj=[]
N, M = map(int, input().split())
for m in range(M):
  a,b=map(int, input().split())
  adj.append([a-1,b-1])

ans = 0
for i in range(M):
  uf = UnionFind(N)
  for j in range(M):
    if i == j:
      continue
    uf.union(*adj[j])
  if len(set(uf.roots()))!=1:
    ans += 1
print(ans)

Solution (Python):
from collections import deque
N, M = map(int, input().split())

h = [[]*N for _ in range(N)]
AB = []

for _ in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    h[a].append(b)
    h[b].append(a)
    AB.append([a, b])

ans = 0

for i in range(M):
    a, b = AB[i]
    h[a].remove(b)
    h[b].remove(a)
    
    fl = [False]*N

    q = deque([0])
    while q:
        t = q.popleft()
        if fl[t]:
            continue
        fl[t] = True
        for tt in h[t]:
            q.append(tt)
    
    if not all(fl):
        ans += 1

    h[a].append(b)
    h[b].append(a)

print(ans)

Solution (Python):
N,M = map(int,input().split())
s = [[] for i in range(N)]
m = []
for i in range(M):
    a,b = map(int,input().split())
    s[a-1].append(b)
    s[b-1].append(a)
    m.append([a,b])
ans = 0
from collections import deque
import copy
d = deque()
for i in range(M):
    n = [0] * N
    a = m[i][0]
    b = m[i][1]
    c = s[a-1].copy()
    c.remove(b)
    d.append(c)
    n[a-1] = 1
    while len(d) > 0:
        e = d.popleft()
        for j in e:
            if n[j-1] == 0:
                n[j-1] = 1
                d.append(s[j-1])
    if 0 in n:
        ans += 1
print(ans)

Solution (Python):

class node:
    def __init__(self, id):
        self.id = id
        self.root = self

    def findRoot(self):
        if self == self.root:
            return self
        else:
            self.root = self.root.findRoot()
            return self.root

    def resetRoot(self):
        self.root = self

class Tree:
    def __init__(self, num):
        self.nodes = {i:node(i) for i in range(num)}

    def union(self, one, other):
        root1 = one.findRoot()
        root2 = other.findRoot()
        root1.root = root2.root = self.nodes[min(root1.id, root2.id)]

    def resetTree(self):
        for n in self.nodes.values():
            n.resetRoot()

    def makeTree(self, Edge):
        self.edge = Edge
        for x,y in Edge:
            self.union(self.nodes[x-1], self.nodes[y-1])


def main():
    with open(0) as f:
        N, M = map(int, f.readline().split())
        Edge = [tuple(map(int, line.split())) for line in f.readlines()]
    
    tree = Tree(N)
    ans = 0
    for i in range(M):
        edge = [v for  v in Edge if v != Edge[i]]
        tree.makeTree(edge)
        if any(x.findRoot().id != 0 for x in tree.nodes.values()):
            ans += 1
        tree.resetTree()
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x,  y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return list(i for i in range(self.n) if self.find(i) == root)

    def roots(self):
        return list(i for i, x in enumerate(self.parents) if x < 0)

    def group_count(self):
        return len(self.roots)

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

adj =  []
N, M = map(int, input().split())
for m in range(M):
    a,b = map(int, input().split())
    adj.append([a-1, b-1])

ans = 0
for i in range(M): 
    uf = UnionFind(N)
    for j in range(M): 
        if i == j:
            continue
        uf.union(*adj[j])
    if len(set(uf.roots())) != 1:
        ans += 1
print(ans)

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,m = i_map()
    ab = [i_list() for i in range(m)]

    def dfs(table):
        visited = [1]
        que = [1]

        while que != []:
            now = que[0]
            del que[0]

            for index, e in enumerate(table[now]):
                if (e==1) & (index not in visited):
                    visited.append(index)
                    que.append(index)
        if len(visited) == n:
            return 0
        else:
            return 1

    ans = 0
    for i in range(m):
        graph = ab.copy()
        del graph[i]
        table = [[0]*(n+1) for i in range(n+1)]
        for a,b in graph:
            table[a][b] = 1
            table[b][a] = 1

        ans += dfs(table)
    print(ans)



if __name__=="__main__":
    main()

Solution (Python):
from collections import deque

N, M = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(M)]
routings = [[] for _ in range(N+1)]
for a, b in edges:
  routings[a].append(b)
  routings[b].append(a)

answer = 0
for a, b in edges:
  route = deque([])
  cnt = 0
  checked = [False for i in range(N+1)]
  for r in routings[1]:
    if a == 1 and b == r:
      continue
    else:
      route.append(r)
      cnt += 1
      checked[r] = True
  while len(route) > 0:
    current = route.popleft()
    for next in routings[current]:
      if not checked[next] and (min(current, next) != a or max(current, next) != b):
        route.append(next)
        cnt += 1
        checked[next] = True
  if cnt < N:
    answer += 1
print(answer)

Solution (Python):
class UnionFind():
    def __init__(self,N):
        self.par=[-1]*N
    
    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.par[x] > self.par[y]:
            x,y = y,x
        self.par[x] += self.par[y]
        self.par[y] = x
        return True
    
    def root(self,x):
        if self.par[x]<0:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]
    
    def size(self,x):
        return -self.par[self.root(x)]

N,M = map(int,input().split())
Edge = []
for _ in range(M):
    u,v = map(int,input().split())
    Edge.append((u-1,v-1))

ans = 0

for e in Edge:
    uf = UnionFind(N)
    for _e in Edge:
        if e == _e:
            continue
        uf.unite(_e[0],_e[1])
    if uf.size(0) != N:
        ans += 1

print(ans)

Solution (Python):
import sys


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1


def check(G, n):
    for a in range(n):
        for b in range(a+1, n):
            if G._root(a) != G._root(b):
                return True
    return False


def main():
    n, m = map(int, sys.stdin.buffer.readline().split())
    ab = [list(map(int, x.split())) for x in sys.stdin.buffer.readlines()]
    ans = 0
    for i in ab:
        G = UnionFind(n)
        for j in ab:
            if i != j:
                G.union(j[0]-1, j[1]-1)
        if check(G, n):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from typing import List, Tuple


def main():
    n, m = map(int, input().split())
    g = []
    for _ in range(m):
        a, b = map(int, input().split())
        g.append((a, b))
    print(br(n, m, g))


def br(n: int, m: int, g: List[Tuple[int, int]]):
    ret = 0
    for i in range(m):
        v = set()
        w = [1]
        while w:
            now = w.pop()
            v.add(now)
            for j, node in enumerate(g):
                if j == i:
                    continue
                if node[0] == now and node[1] not in v:
                    w.append(node[1])
                elif node[1] == now and node[0] not in v:
                    w.append(node[0])
        if len(v) != n:
            ret += 1
    return ret


if __name__ == '__main__':
    main()

Solution (Python):
from typing import List, Tuple


def main():
    n, m = map(int, input().split())
    g = []
    for _ in range(m):
        a, b = map(int, input().split())
        g.append((a, b))
    print(bb(n, m, g))


def bb(n: int, m: int, g: List[Tuple[int, int]]):
    ret = 0
    for i in range(m):
        v = set()
        w = [1]
        while w:
            now = w.pop()
            v.add(now)
            for j, node in enumerate(g):
                if j == i:
                    continue
                if node[0] == now and node[1] not in v:
                    w.append(node[1])
                elif node[1] == now and node[0] not in v:
                    w.append(node[0])
        if len(v) != n:
            ret += 1
    return ret


if __name__ == '__main__':
    main()

Solution (Python):
import queue

n, m = map(int, input().split())
am_bm = []
side_map = dict()
for i in range(m):
    ai, bi = map(int, input().split())
    if ai not in side_map:
        side_map[ai] = set()
        side_map[ai].add(bi)
    else:
        side_map[ai].add(bi)
    if bi not in side_map:
        side_map[bi] = set()
        side_map[bi].add(ai)
    else:
        side_map[bi].add(ai)
    am_bm.append((ai, bi))

counter = 0
for i in range(m):
    a, b = am_bm[i]
    q = queue.Queue()
    q.put(1)
    node_passed = set()
    node_passed.add(1)
    while not q.empty():
        a_tmp = q.get()
        for b_tmp in side_map[a_tmp]:
            if a_tmp == a and b_tmp == b or a_tmp == b and b_tmp == a:
                pass
            elif b_tmp not in node_passed:
                q.put(b_tmp)
                node_passed.add(b_tmp)
    if len(node_passed) == n:
        counter += 1
print(m - counter)

Solution (Python):
n, m = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(m)]

def find(x):
    if root[x] < 0:
        return x
    else:
        root[x] = find(root[x])
        return root[x]

def unit(x, y):
    gx = find(x)
    gy = find(y)

    if gx == gy:
        return

    if root[gx] > root[gy]:
        gx, gy = gy, gx

    root[gx] += root[gy]
    root[gy] = gx

cnt = 0
for i in range(m):
    root = [-1] * n
    for j in range(m):
        if i == j:continue
        unit(AB[j][0]-1, AB[j][1]-1)
    roots = [i for i in root if i < 0]
    cnt += (len(roots) != 1)
print(cnt)

Solution (Python):
N,M=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

ans=0
for i in range(M):
    uf=UnionFind(N)
    for j in range(M):
        if i==j:
            continue
        a,b=ab[j]
        uf.union(a-1,b-1)
    ans+=(uf.group_count()>1)
print(ans)

Solution (Python):
N,M=map(int,input().split())
graph=[]
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return
for i in range(M):
  a,b=map(int,input().split())
  graph.append((a-1,b-1))
bridge=0
from collections import Counter
for i in range(M):
  par=[i for i in range(N)]
  size=[1 for i in range(N)] 
  for j in range(M):
    if j!=i:
      union(graph[j][0],graph[j][1])
  if N not in size:
    bridge+=1
print(bridge)

Solution (Python):
import copy
        
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

class UnionFindPathCompression():
    def __init__(self, n:int):
        self.parents = list(range(n))
        self.rank = [1]*n
        self.size = [1]*n
        

    def find(self, x:int) -> int:
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x:int, y:int):
        px = self.find(x)
        py = self.find(y)

        if px == py:
            return
        else:
            if self.rank[px] < self.rank[py]:
                self.parents[px] = py
                self.size[py] += self.size[px]
            else:
                self.parents[py] = px
                self.size[px] += self.size[py]
                
                if self.rank[px] == self.rank[py]:
                    self.rank[px] += 1


n,m = map(int,input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ans = 0
for i in range(m):
    ufpc = UnionFindPathCompression(n)
    ab_copy = copy.deepcopy(ab)
    ab_copy.pop(i)
    for a,b in ab_copy:
        a,b = a-1,b-1
        ufpc.union(a,b)
    for i in range(n):
        ufpc.find(i)
    check = set(ufpc.parents)
    if len(check) != 1:
        ans += 1
print(ans)

Solution (Python):
import copy
        
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

class UnionFindPathCompression():
    def __init__(self, n:int):
        self.parents = list(range(n))
        self.rank = [1]*n
        self.size = [1]*n
        

    def find(self, x:int) -> int:
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x:int, y:int):
        px = self.find(x)
        py = self.find(y)

        if px == py:
            return
        else:
            if self.rank[px] < self.rank[py]:
                self.parents[px] = py
                self.size[py] += self.size[px]
            else:
                self.parents[py] = px
                self.size[px] += self.size[py]
                
                if self.rank[px] == self.rank[py]:
                    self.rank[px] += 1


n,m = map(int,input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
memo = 0
for i in range(m):
    ufpc = UnionFindPathCompression(n)
    ab_copy = copy.deepcopy(ab)
    ab_copy.pop(i)
    for a,b in ab_copy:
        a,b = a-1,b-1
        ufpc.union(a,b)
    for i in range(n):
        ufpc.find(i)
    check = set(ufpc.parents)
    if len(check)==1:
        memo += 1
print(m-memo)

Solution (Python):
class DisjointSet:
    def __init__(self, size):
        self.size = [0 for i in range(size)]
        self.p = [0 for i in range(size)]
        for i in range(size):
            self.makeSet(i)
    
    def makeSet(self, x):
        self.p[x] = x
        self.size[x] = 1

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.size[x] > self.size[y]:
            self.p[y] = x
            self.size[x] += self.size[y]
        else:
            self.p[x] = y
            self.size[y] += self.size[x]
    
    def findSet(self, x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]

    def getSize(self, x):
        return self.size[ds.findSet(x)]

N, M = map(int, input().split())
A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    A += [a]
    B += [b]
ans = 0
for i in range(M):
    ds = DisjointSet(N+1)
    for j, (a, b) in enumerate(zip(A, B)):
        if i == j:
            continue
        ds.unite(a, b)
    if len(set([ds.findSet(j) for j in range(1, N+1)])) != 1:
        ans += 1
print(ans)

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


class UnionFind:
    def __init__(self,n):
        self.par = [i for i in range(n+1)]  
        self.rank = [0]*(n+1)
    def find(self,x):  
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self,x,y):  
        return self.find(x) == self.find(y)
    def unite(self,x,y):  
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            x,y = y,x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.par[y] = x


N,M = MI()
edges = [tuple(MI()) for _ in range(M)]

ans = 0
for i in range(M):
    U = UnionFind(N)
    for j in range(M):
        if j != i:
            a,b = edges[j]
            U.unite(a,b)
    x,y = edges[i]
    if not U.same_check(x,y):
        ans += 1

print(ans)

Solution (Python):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x): 
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y): 
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x): 
        return -self.parents[self.find(x)]

    def same(self, x, y): 
        return self.find(x) == self.find(y)

    def members(self, x): 
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self): 
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self): 
        return len(self.roots())

    def all_group_members(self): 
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
l=[]
for i in range(m):
    l.append(list(map(int,input().split())))
ans=0
for i in range(m):
    a=UnionFind(n)
    for j in range(m):
        if i==j:
            continue
        a.union(l[j][0]-1,l[j][1]-1)
    if a.group_count()==2:
        ans+=1
print(ans)

Solution (Python):
import sys
from collections import deque

input = sys.stdin.readline
N, M = map(int, input().split())

edges = [[] for _ in range(N)]
edge_set = set()
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

    edge_set.add((a, b))

ans = 0
for a, b in edge_set:
    q = deque()
    q.append(0)
    visited = set()
    while q:
        p = q.popleft()
        if p in visited:
            continue
        visited.add(p)
        for np in edges[p]:
            if (p, np) == (a, b) or (np, p) == (a, b):
                continue
            q.append(np)
    if len(visited) != N:
        ans += 1

print(ans)

Solution (Python):
import copy
import sys
sys.setrecursionlimit(10**7)

N, M = map(int, input().split())
G = [[] for _ in range(N)]
side = []
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    G[a].append(b)
    G[b].append(a)
    side.append((a,b))

def dfs(v,G):
    seen[v] = True
    for next_v in G[v]:
        if seen[next_v] == True:
             continue
        dfs(next_v,G)

bridge = 0

for a,b in side:
    Gc = copy.deepcopy(G)
    Gc[a].remove(b)
    Gc[b].remove(a)
    seen = [False]*N
    cnt = 0
    
    for s in range(N):
        if seen[s] == True:
            continue
        cnt += 1
        dfs(s,Gc)
    
    if cnt>=2:
        bridge += 1
print(bridge)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
edges = [inpl() for _ in range(m)]
res = 0
for ind in range(m):
    e = [[] for _ in range(n)]
    for i,(a,b) in enumerate(edges):
        if i == ind: continue
        e[a-1].append(b-1)
        e[b-1].append(a-1)
    seen = [False]*n
    cnt = 0
    for i in range(n):
        if seen[i]: continue    
        q = deque([])
        q.append(i)
        cnt += 1
        while q:
            now = q.popleft()
            if seen[now]: continue
            seen[now] = True
            for nx in e[now]:
                if seen[nx]: continue
                q.append(nx)
    if cnt != 1:
        res += 1
print(res)

Solution (Python):
from collections import deque
N,M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(M)]
cnt = 0
for x in A:
    G = {i:[] for i in range(1,N+1)}
    for y in A:
        if y!=x:
            a,b = y
            G[a].append(b)
            G[b].append(a)
    hist = [0 for _ in range(N+1)]
    que = deque([1])
    hist[1] = 1
    while que:
        z = que.popleft()
        for w in G[z]:
            if hist[w]==0:
                que.append(w)
                hist[w]=1
    if sum(hist)<N:
        cnt += 1
print(cnt)