How to use make_set method in Slash

Best Python code snippet using slash

test_dsu.py

Source:test_dsu.py Github

copy

Full Screen

...7from graph_algorithms.exception.graph_exception import DataStructureIsEmptyException8from graph_algorithms.exception.messages import data_structure_is_empty_message9def test_find_negative1():10 s = DSU()11 s.make_set(1)12 with pytest.raises(NotContainsElementException) as exception_info:13 s.find(5)14 assert str(exception_info.value) == not_contains_element_message()15def test_find_negative2():16 s = DSU()17 with pytest.raises(DataStructureIsEmptyException) as exception_info:18 s.find(11)19 assert str(exception_info.value) == data_structure_is_empty_message()20def test_find_positive():21 s = DSU()22 s.make_set(1)23 s.make_set(2)24 s.make_set(3)25 s.make_set(4)26 assert s.find(1) == 127 assert s.find(2) == 228 assert s.find(3) == 329 assert s.find(4) == 430def test_unite1():31 s = DSU()32 s.make_set(1)33 s.make_set(2)34 s.make_set(3)35 s.make_set(4)36 s.make_set(5)37 s.unite(1, 4)38 s.unite(3, 5)39 assert s.find(1) == s.find(4)40 assert s.find(5) == s.find(5)41 assert s.find(2) == 242def test_unite2():43 s = DSU()44 s.make_set(2)45 s.make_set(4)46 s.make_set(6)47 s.make_set(8)48 s.make_set(10)49 s.unite(2, 4)50 s.unite(6, 8)51 assert s.find(2) == s.find(4)52 assert s.find(6) == s.find(8)53 s.unite(8, 2)54 assert s.find(2) == s.find(8)55 assert s.find(2) == s.find(4)56 assert s.find(2) == s.find(6)57 s.unite(6, 10)58 assert s.find(2) == s.find(8)59 assert s.find(2) == s.find(4)60 assert s.find(2) == s.find(6)...

Full Screen

Full Screen

10216_Count_Circle_Groups_version1.py

Source:10216_Count_Circle_Groups_version1.py Github

copy

Full Screen

1import sys2def input():3 return sys.stdin.readline().rstrip()4def find_parents(x,make_set):5 if make_set[x] == x:6 return x7 make_set[x] = find_parents(make_set[x],make_set)8 return make_set[x]9def union(x,y,make_set):10 X = find_parents(x,make_set)11 Y = find_parents(y,make_set)12 if X<Y:13 make_set[Y] = make_set[X]14 else:15 make_set[X] = make_set[Y] 16def solve():17 N = int(input())18 nodes = []19 make_set = [i for i in range(N)]20 nodes = [list(map(int,input().split())) for _ in range(N)]21 for a1 in range(N-1):22 for a2 in range(a1+1,N):23 x1,y1,r1 = nodes[a1]24 x2,y2,r2 = nodes[a2]25 if (x1-x2)**2 + (y1-y2)**2 <= (r1+r2)**2:26 if find_parents(a1,make_set) == find_parents(a2,make_set):continue27 union(a1,a2,make_set)28 ans = 029 for ind in range(N):30 if find_parents(ind,make_set) == ind:31 ans += 132 print(ans)33if __name__ == "__main__":34 T = int(input())35 for _ in range(T):...

Full Screen

Full Screen

disjoint_set_forest.py

Source:disjoint_set_forest.py Github

copy

Full Screen

1# implementation of disjoint set data structure2# using forests and union by rank and path compression3 4class Disjoint_Set_Forest:5 def Make_Set(self,x):6 x.P = x7 8 def Find_Set(self,x):9 if x != x.P:10 x.P = self.Find_Set(x.P)11 return x.P12 13 def Link(self,x,y):14 if x.Rank > y.Rank:15 y.P = x16 else:17 x.P = y18 if x.Rank == y.Rank:19 y.Rank+=120 21 def Union(self,x,y):22 self.Link(self.Find_Set(x),self.Find_Set(y))23 24 25 26 27def main():28 from weighted_graph import Vertex29 30 DSF = Disjoint_Set_Forest()31 a = Vertex("a")32 DSF.Make_Set(a)33 b = Vertex("b")34 DSF.Make_Set(b)35 c = Vertex("c")36 DSF.Make_Set(c)37 d = Vertex("d")38 DSF.Make_Set(d)39 e = Vertex("e")40 DSF.Make_Set(e)41 DSF.Union(a,b)42 DSF.Union(c,d)43 print(DSF.Find_Set(a).Key)44 DSF.Union(b,c)45 print(DSF.Find_Set(a).Key)46 47if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful