classUnion:def__init__(self): self.parnet =list(range(26))@staticmethoddefc2n(char):returnord(char)-97@staticmethoddefn2c(num):returnchr(num +97)deffind(self,char): num = self.c2n(char)if self.parnet[num]== num:return num self.parnet[num]= self.find(self.n2c(self.parnet[num]))return self.parnet[num]defunion(self,char1,char2): self.parnet[self.find(char1)]= self.find(char2)defconnected(self,char1,char2):return self.find(char1)== self.find(char2)classSolution:defequationsPossible(self,equations: List[str]) ->bool: u =Union() not_equal = []for s in equations: x, y, op = s[0], s[3], s[1]if op =='=': u.union(x, y)else: not_equal.append((x, y))for x, y in not_equal:if u.connected(x, y):returnFalsereturnTrue