human
Can you provide a Python program to find the speed of rotation of gear $Y$ if gear $X$ rotates with speed $V$ given the following:
I found an interesting problem on https://www.codechef.com/problems/GEARS:
You are given $N$ gears numbered $1$ through $N$. For each valid $i$, gear $i$ has $A_i$ teeth. In the beginning, no gear is connected to any other. Your task is to process $M$ queries and simulate the gears' mechanism. There are three types of queries:
- Type 1: Change the number of teeth of gear $X$ to $C$.
- Type 2: Connect two gears $X$ and $Y$.
- Type 3: Find the speed of rotation of gear $Y$ if gear $X$ rotates with speed $V$.
It is known that if gear $i$ is directly connected to gear $j$ and gear $i$ rotates with speed $V$, then gear $j$ will rotate with speed $-V A_i / A_j$, where the sign of rotation speed denotes the direction of rotation (so minus here denotes rotation in the opposite direction). You may also notice that gears can be blocked in some cases. This happens when some gear would have to rotate in different directions. If a gear is connected to any blocked gear, it is also blocked. For example, if three gears are connected to each other, this configuration can not rotate at all, and if we connect a fourth gear to these three, it will also be blocked and not rotate.

-----Input-----
- The first line of the input contains two space-separated integers $N$ and $M$.
- The second line contains $N$ space-separated integers $A_1, A_2, \dots, A_N$.
- The following $M$ lines describe queries. Each of these lines begins with an integer $T$ denoting the type of the current query.
- If $T = 1$, it is followed by a space and two space-separated integers $X$ and $C$.
- If $T = 2$, it is followed by a space and two space-separated integers $X$ and $Y$.
- If $T = 3$, it is followed by a space and three space-separated integers $X$, $Y$ and $V$.

-----Output-----
For each query of type 3, print a single line containing two integers separated by a slash '/' — the numerator and denominator of the rotation speed of the given gear expressed as an irreducible fraction (even if this speed is an integer), or $0$ if the gear does not rotate at all.

-----Constraints-----
- $1 \le N \le 10^5$
- $1 \le M \le 2\cdot...

I tried it in Python, but could not do it. Can you solve it?
assistant
#Here is Python program to find the speed of rotation of gear $Y$ if gear $X$ rotates with speed $V$.

class Dsu:
    def __init__(self, v, s):
        self.par = s
        self.v = v
        self.dr = [1] * v
        self.zero = [False] * v
        self.speed = []
        for i in range(v):
            self.speed.append([])
            self.speed[i].append(i)

    def find(self, i):
    #     if parent[i] == -1:
    #         return i
    #     else: return self.find_parent(parent, parent[i])
        if i != self.par[i][0]:
            org = self.par[i][0]
            self.par[i][0] = self.find(self.par[i][0])
            if self.zero[i] or self.zero[self.par[i][0]] or self.zero[org]:
                self.zero[i] = self.zero[self.par[i][0]] = self.zero[org] = True
            if org != self.par[i][0]:
                self.speed[self.par[i][0]].append(i)
        return self.par[i][0]

    def union(self, x, y):
        # def union(self, parent, x, y):
        #     x_set = self.find_parent(parent, x)
        #     y_set = self.find_parent(parent, y)
        #     parent[x_set] = y_set
        self.rx = self.find(x)
        self.ry = self.find(y)
        self.sign = -self.dr[x] * self.dr[y]
        if self.rx != self.ry:
            if (self.par[self.rx][1]<self.par[self.ry][1]):
                mx=self.ry
                mn=self.rx
            if (self.par[self.rx][1]>self.par[self.ry][1]):
                mx=self.rx
                mn=self.ry
            if self.par[self.rx][1] != self.par[self.ry][1]:
                self.par[mn][0] = mx
                if self.zero[mn] or self.zero[mx] or self.zero[x] or self.zero[y]:
                    self.zero[mn] = self.zero[mx] = self.zero[x] = self.zero[y] = True
                else:
                    for i in range(len(self.speed[mn])):
                        self.dr[self.speed[mn][i]] *= self.sign
                        org = self.par[self.speed[mn][i]][0]
                        if org != mx:
                            self.par[self.speed[mn][i]][0] = mx
                            self.speed[mx].append(self.speed[mn][i])
               ...