Problem: Takahashi likes the sound when he buys a drink from a vending machine.  That sound can be heard by spending A yen (the currency of Japan) each time.  Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time.  How many times will he hear the sound?

Submission attempts (in order):
N, M = list(map(int,input().split()))
A = []
B = []
for i in range(M):
    A1,B1=[int(i) for i in input().split()]
    A.append(A1)
    B.append(B1)
A.reverse()
B.reverse()

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n+1)]
        self.rank = [0 for _ in range(n+1)]
        self.size = [1 for _ in range(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 union(self, x, y):
        
        x = self.find(x)
        y = self.find(y)
        if x != y:
            x_size = self.size[x]
            y_size = self.size[y]
            sum_size = x_size + y_size
            self.size[x] = sum_size
            self.size[y] = sum_size
            
            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

    def is_same(self, x, y):
        
        return self.find(x) == self.find(y)
    
    def get_size(self, a):
        x = self.find(a)
        return self.size[x]
      
uf = UnionFind(N)
anses = []
ans = N * (N-1) // 2
anses.append(ans)

for k in range(len(A)-1):
    if uf.is_same(A[k], B[k]):
        anses.append(anses[k])
        print(anses)
    else:
        N1 = uf.get_size(A[k])
        N2 = uf.get_size(B[k])
        ans = anses[k] - (N1 * N2)
        if ans < 0:
            ans = 0
        uf.union(A[k], B[k])
        anses.append(ans)
        
for ans in reversed(anses):
        print(ans)

N, M = list(map(int,input().split()))
A = []
B = []
for i in range(M):
    A1,B1=[int(i) for i in input().split()]
    A.append(A1)
    B.append(B1)
A.reverse()
B.reverse()

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n+1)]
        self.rank = [0 for _ in range(n+1)]
        self.size = [1 for _ in range(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 union(self, x, y):
        
        x = self.find(x)
        y = self.find(y)
        if x != y:
            x_size = self.size[x]
            y_size = self.size[y]
            sum_size = x_size + y_size
            self.size[x] = sum_size
            self.size[y] = sum_size
            
            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

    def is_same(self, x, y):
        
        return self.find(x) == self.find(y)
    
    def get_size(self, a):
        x = self.find(a)
        return self.size[x]
      
uf = UnionFind(N)
anses = []
ans = int(N * (N-1) / 2)
anses.append(ans)

for k in range(len(A)-1):
    if uf.is_same(A[k], B[k]):
        anses.append(anses[k])
        print(anses)
    else:
        N1 = uf.get_size(A[k])
        N2 = uf.get_size(B[k])
        ans = anses[k] - (N1 * N2)
        if ans < 0:
            ans = 0
        uf.union(A[k], B[k])
        anses.append(ans)
        
for ans in reversed(anses):
        print(ans)

a, b, c = list(map(int,input().split()))
q = int(b / a)
if q > c:
    print(c)
else:
    print(q)

Verdicts: Runtime Error

Runtime Error

Accepted