锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品久久网,欧美国产乱视频,欧美精品一区二区三区在线看午夜http://www.shnenglu.com/Uriel/articles/230018.htmlUrielUrielSun, 20 Aug 2023 02:56:00 GMThttp://www.shnenglu.com/Uriel/articles/230018.htmlhttp://www.shnenglu.com/Uriel/comments/230018.htmlhttp://www.shnenglu.com/Uriel/articles/230018.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/230018.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/230018.html
瀹氫箟錛?br />
An MST edge whose deletion from the graph would cause the MST weight to increase is called a critical edge. On the other hand, a pseudo-critical edge is that which can appear in some MSTs but not all.

騫舵煡闆嗘眰MST+鏋氫婦杈癸紝鎬濊礬鍙傝?>https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/solutions/3929349/detailed-video-solution-java-c-python/


 1 #1489
 2 #Runtime: 2134 ms (Beats 50%)
 3 #Memory: 13.4 MB (Beats 100%)
 4 
 5 class UnionFind:
 6     def __init__(self, n):
 7         self.pa = list(range(n))
 8 
 9     
10     def find(self, x):
11         if self.pa[x] != x:
12             self.pa[x] = self.find(self.pa[x])
13         return self.pa[x]
14 
15 
16     def union(self, x, y):
17         px, py = self.find(x), self.find(y)
18         self.pa[px] = py
19 
20 
21 class Solution(object):
22     def findCriticalAndPseudoCriticalEdges(self, n, edges):
23         """
24         :type n: int
25         :type edges: List[List[int]]
26         :rtype: List[List[int]]
27         """
28         def find_MST(block, e):
29             uf = UnionFind(n)
30             wt = 0
31             if e != -1:
32                 wt += edges[e][2]
33                 uf.union(edges[e][0], edges[e][1])
34             for i in range(len(edges)):
35                 if i == block:
36                     continue
37                 if uf.find(edges[i][0]) == uf.find(edges[i][1]):
38                     continue
39                 uf.union(edges[i][0], edges[i][1])
40                 wt += edges[i][2]
41             for i in range(n):
42                 if uf.find(i) != uf.find(0):
43                     return float('inf')
44             return wt
45 
46         c = []
47         pc = []
48         for i, e in enumerate(edges):
49             e.append(i)
50         edges.sort(key=lambda x: x[2])
51         mst = find_MST(-1, -1)
52         for i, e in enumerate(edges):
53             if mst < find_MST(i, -1):
54                 c.append(e[3])
55             elif mst == find_MST(-1, i):
56                 pc.append(e[3])
57         return [c, pc]


Uriel 2023-08-20 10:56 鍙戣〃璇勮
]]>
[LeetCode]547. Number of Provinces (Medium) Python-2023.06.04http://www.shnenglu.com/Uriel/articles/229918.htmlUrielUrielSun, 04 Jun 2023 15:18:00 GMThttp://www.shnenglu.com/Uriel/articles/229918.htmlhttp://www.shnenglu.com/Uriel/comments/229918.htmlhttp://www.shnenglu.com/Uriel/articles/229918.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/229918.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/229918.html姹傛棤鍚戝浘鐨勮仈閫氬垎鏀釜鏁幫紝DFS | BFS | 騫舵煡闆?鍩烘湰緇冧範

DFS
 1 #547
 2 #Runtime: 154 ms (Beats 66.8%)
 3 #Memory: 13.6 MB (Beats 94.53%)
 4 
 5 class Solution(object):
 6     def findCircleNum(self, isConnected):
 7         """
 8         :type isConnected: List[List[int]]
 9         :rtype: int
10         """
11         ans = 0
12         n = len(isConnected)
13         vis = [0] * n
14 
15         def DFS(node):
16             vis[node] = 1
17             for i in range(n):
18                 if isConnected[node][i] == 1 and not vis[i]:
19                     DFS(i)
20         
21         for i in range(n):
22             if not vis[i]:
23                 DFS(i)
24                 ans += 1
25         return ans


BFS
 1 #547
 2 #Runtime: 156 ms (Beats 61.49%)
 3 #Memory: 13.8 MB (Beats 40.4%)
 4 
 5 class Solution(object):
 6     def findCircleNum(self, isConnected):
 7         """
 8         :type isConnected: List[List[int]]
 9         :rtype: int
10         """
11         ans = 0
12         n = len(isConnected)
13         vis = [0] * n
14         for i in range(n):
15             if not vis[i]:
16                 q = deque([i])
17                 vis[i] = 1
18                 ans += 1
19                 while q:
20                     x = q.popleft()
21                     for j in range(n):
22                         if not vis[j] and isConnected[x][j]:
23                             vis[j] = 1
24                             q.append(j)
25         return ans


騫舵煡闆?br />
 1 #547
 2 #Runtime: 178 ms (Beats 21.88%)
 3 #Memory: 13.5 MB (Beats 94.53%)
 4 
 5 class Solution(object):
 6     def findCircleNum(self, isConnected):
 7         """
 8         :type isConnected: List[List[int]]
 9         :rtype: int
10         """
11         n = len(isConnected)
12         parent = [i for i in range(n)]
13 
14         def find(x):
15             if parent[x] != x:
16                 parent[x] = find(parent[x])
17             return parent[x]
18 
19         def union(x, y):
20             fa, fb = find(x), find(y)
21             parent[fb] = fa
22 
23         for i in range(n):
24             for j in range(n):
25                 if isConnected[i][j]:
26                     union(i, j)
27         return len(set([find(i) for i in range(n)]))


Uriel 2023-06-04 23:18 鍙戣〃璇勮
]]>
[LeetCode]399. Evaluate Division (Medium) Python-2023.05.20http://www.shnenglu.com/Uriel/articles/229897.htmlUrielUrielSat, 20 May 2023 10:27:00 GMThttp://www.shnenglu.com/Uriel/articles/229897.htmlhttp://www.shnenglu.com/Uriel/comments/229897.htmlhttp://www.shnenglu.com/Uriel/articles/229897.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/229897.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/229897.html
鎬濊礬涓錛氬緩鍥撅紝BFS
鎬濊礬浜岋細騫舵煡闆嗭紝鍐欐硶鍙傝冧簡Discussion


 1 #399
 2 #Runtime: 25 ms (Beats 11.39%)
 3 #Memory: 13.4 MB (Beats 73.42%)
 4 
 5 class Solution(object):
 6     def calcEquation(self, equations, values, queries):
 7         """
 8         :type equations: List[List[str]]
 9         :type values: List[float]
10         :type queries: List[List[str]]
11         :rtype: List[float]
12         """
13         equ = {}
14 
15         def find(x):
16             p, v = equ.setdefault(x, (x, 1))
17             if x != p:
18                 r, w = find(p)
19                 equ[x] = (r, w * v)
20             return equ[x]
21             
22         def union(x, y, v):
23             px, pv = find(x)
24             py, pw = find(y)
25             if not v:
26                 if px == py:
27                     return pv / pw
28                 else:
29                     return -1
30             if px != py:
31                 equ[px] = (py, pw / pv * v)
32 
33         for (x, y), v in zip(equations, values):
34             union(x, y ,v)
35         ans = []
36         for x, y in queries:
37             if x in equ and y in equ:
38                 ans.append(union(x, y, 0))
39             else:
40                 ans.append(-1)
41         return ans
42 


Uriel 2023-05-20 18:27 鍙戣〃璇勮
]]>
[LeetCode]785. Is Graph Bipartite? (Medium) Python-2023.05.19http://www.shnenglu.com/Uriel/articles/229896.htmlUrielUrielFri, 19 May 2023 12:26:00 GMThttp://www.shnenglu.com/Uriel/articles/229896.htmlhttp://www.shnenglu.com/Uriel/comments/229896.htmlhttp://www.shnenglu.com/Uriel/articles/229896.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/229896.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/229896.html
 1 #785
 2 #Runtime: 160 ms (Beats 23.18%)
 3 #Memory: 13.6 MB (Beats 95%)
 4 
 5 class Solution(object):
 6     def isBipartite(self, graph):
 7         """
 8         :type graph: List[List[int]]
 9         :rtype: bool
10         """
11         parent = [i for i in range(len(graph))]
12         
13         def find(x):
14             if parent[x] != x:
15                 parent[x] = find(parent[x])
16             return parent[x]
17         
18         def union(x, y):
19             fa, fb = find(x), find(y)
20             parent[fb] = fa
21         
22         for i in range(len(graph)):
23             for j in range(len(graph[i])):
24                 pi, pj = find(i), find(graph[i][j])
25                 if pi == pj:
26                     return False
27                 union(graph[i][0], graph[i][j])
28         
29         return True


Uriel 2023-05-19 20:26 鍙戣〃璇勮
]]>
[LeetCode]1579. Remove Max Number of Edges to Keep Graph Fully Traversable (Hard) Python-2023.04.30http://www.shnenglu.com/Uriel/articles/229855.htmlUrielUrielSun, 30 Apr 2023 12:07:00 GMThttp://www.shnenglu.com/Uriel/articles/229855.htmlhttp://www.shnenglu.com/Uriel/comments/229855.htmlhttp://www.shnenglu.com/Uriel/articles/229855.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/229855.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/229855.html鎬濊礬鍙傝?>https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable/solutions/3468567 


 1 #1579
 2 #Runtime: 1874 ms (Beats 35.71%)
 3 #Memory: 63.1 MB (Beats 71.43%)
 4 
 5 class UnionFind:
 6     def __init__(self, n):
 7         self.parent = list(range(n + 1))
 8         self.cc = n
 9     def union(self, a, b):
10         fa = self.find(a)
11         fb = self.find(b)
12         if fa == fb:
13             return 0
14         self.parent[fa] = fb
15         self.cc -= 1
16         return 1
17 
18     def find(self, a):
19         if self.parent[a] != a:
20             self.parent[a] = self.find(self.parent[a])
21         return self.parent[a]
22 
23     def judge(self):
24         return self.cc == 1
25 
26 class Solution(object):
27     def maxNumEdgesToRemove(self, n, edges):
28         """
29         :type n: int
30         :type edges: List[List[int]]
31         :rtype: int
32         """
33         alice, bob = UnionFind(n), UnionFind(n)
34 
35         t = 0
36         for a, u, v in edges:
37             if a == 3:
38                 t += alice.union(u, v) | bob.union(u, v)
39             if alice.judge() and bob.judge():
40                 return len(edges) - t
41 
42         for a, u, v in edges:
43             if a == 1:
44                 t += alice.union(u, v)  
45             elif a == 2:
46                 t += bob.union(u, v)
47             if alice.judge() and bob.judge():
48                 return len(edges) - t
49 
50         if not alice.judge() or not bob.judge():
51             return -1
52 
53         return len(edges) - t


Uriel 2023-04-30 20:07 鍙戣〃璇勮
]]>
[LeetCode]1697. Checking Existence of Edge Length Limited Paths (Hard) Python-2023.04.29http://www.shnenglu.com/Uriel/articles/229854.htmlUrielUrielSat, 29 Apr 2023 14:15:00 GMThttp://www.shnenglu.com/Uriel/articles/229854.htmlhttp://www.shnenglu.com/Uriel/comments/229854.htmlhttp://www.shnenglu.com/Uriel/articles/229854.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/229854.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/229854.html

 1 #1697
 2 #Runtime: 1668 ms (Beats 100%)
 3 #Memory: 59.9 MB (Beats 100%)
 4 
 5 class Solution(object):
 6     def distanceLimitedPathsExist(self, n, edgeList, queries):
 7         """
 8         :type n: int
 9         :type edgeList: List[List[int]]
10         :type queries: List[List[int]]
11         :rtype: List[bool]
12         """
13         parent = [i for i in range(n)]
14         rank = [i for i in range(n)]
15         def find(x, limit):
16             while x != parent[x]:
17                 if dis[x] >= limit:
18                     break
19                 x = parent[x]
20             return x
21 
22         def union(x, y, d):
23             fa = find(x, float('inf'))
24             fb = find(y, float('inf'))
25             if fa != fb:
26                 if rank[fa] < rank[fb]:
27                     parent[fa] = fb
28                     dis[fa] = d
29                 else:
30                     parent[fb] = fa
31                     dis[fb] = d
32                     if rank[fa] == rank[fb]:
33                         rank[fa] += 1
34 
35         def judge(x, y, limit):
36             return find(x, limit) == find(y, limit)
37 
38         dis = [0 for _ in range(n)]
39         edgeList.sort(key=lambda x: x[2])
40         for ed in edgeList:
41             union(ed[0], ed[1], ed[2])
42         ans = []
43         for q in queries:
44             ans.append(judge(q[0], q[1], q[2]))
45         return ans


Uriel 2023-04-29 22:15 鍙戣〃璇勮
]]>
[LeetCode]839. Similar String Groups (Hard) Python-2023.04.28http://www.shnenglu.com/Uriel/articles/229851.htmlUrielUrielFri, 28 Apr 2023 16:55:00 GMThttp://www.shnenglu.com/Uriel/articles/229851.htmlhttp://www.shnenglu.com/Uriel/comments/229851.htmlhttp://www.shnenglu.com/Uriel/articles/229851.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/229851.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/229851.html榪欓鍔犱笉鍔犺礬寰勪紭鍖栭熷害宸笉澶?br />

 1 #839
 2 #Runtime: 341 ms (Beats 65.91%)
 3 #Memory: 13.9 MB (Beats 79.55%)
 4 
 5 class Solution(object):
 6     def numSimilarGroups(self, strs):
 7         """
 8         :type strs: List[str]
 9         :rtype: int
10         """
11         fa = [i for i in range(len(strs))]
12         #rank = [0] * len(strs)
13         def find(x):
14             i = x
15             while x != fa[x]:
16                 x = fa[x]
17             fa[i] = x
18             return x
19 
20         def union(a, b):
21             fa[find(a)] = find(b)
22 
23         def is_similar(x, y):
24             tp = 0
25             for i in range(len(x)):
26                 if x[i] != y[i]:
27                     tp += 1
28                     if tp > 2:
29                         return False
30             return True
31         
32         n_group = len(strs)
33         for i in range(len(strs)):
34             for j in range(i + 1, len(strs)):
35                 if find(i) != find(j) and is_similar(strs[i], strs[j]):
36                     n_group -= 1
37                     union(i, j)
38         return n_group


Uriel 2023-04-29 00:55 鍙戣〃璇勮
]]>
[LeetCode]2316. Count Unreachable Pairs of Nodes in an Undirected Graph (Medium) Python-2023.03.25http://www.shnenglu.com/Uriel/articles/229778.htmlUrielUrielSat, 25 Mar 2023 09:22:00 GMThttp://www.shnenglu.com/Uriel/articles/229778.htmlhttp://www.shnenglu.com/Uriel/comments/229778.htmlhttp://www.shnenglu.com/Uriel/articles/229778.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/229778.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/229778.html鐢ㄥ茍鏌ラ泦搴旇浼氭洿蹇?br />

 1 #2316
 2 #Runtime: 2121 ms (Beats 54.5%)
 3 #Memory: 114.9 MB (Beats 16.22%)
 4 
 5 class Solution(object):
 6     def countPairs(self, n, edges):
 7         """
 8         :type n: int
 9         :type edges: List[List[int]]
10         :rtype: int
11         """
12         edge = defaultdict(list)
13         for x, y in edges:
14             edge[x].append(y)
15             edge[y].append(x)
16         vis = [0] * n
17 
18         def DFS(node):
19             vis[node] = 1
20             self.tp += 1
21             for y in edge[node]:
22                 if not vis[y]:
23                     DFS(y)
24 
25         ncc = []
26         ans = 0
27         for i in range(n):
28             if not vis[i]:
29                 self.tp = 0
30                 DFS(i)
31                 ncc.append(self.tp)
32         total = 0
33         for j in range(len(ncc)):
34             ans += (n - total - ncc[j]) * ncc[j]
35             total += ncc[j]
36         return ans


Uriel 2023-03-25 17:22 鍙戣〃璇勮
]]>
[LeetCode]2421. Number of Good Paths (Hard) Python-2023.01.15http://www.shnenglu.com/Uriel/articles/229628.htmlUrielUrielSun, 15 Jan 2023 13:24:00 GMThttp://www.shnenglu.com/Uriel/articles/229628.htmlhttp://www.shnenglu.com/Uriel/comments/229628.htmlhttp://www.shnenglu.com/Uriel/articles/229628.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/229628.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/229628.html鍙傝冧簡Discussion錛歨ttps://leetcode.com/problems/number-of-good-paths/solutions/3053513/python3-union-find-explained/

 1 #2421
 2 #Runtime: 2295 ms (Beats 93.75%)
 3 #Memory: 39 MB (Beats 81.25%)
 4 
 5 class UnionFind:
 6     def __init__(self, n):
 7         self.parent = [i for i in range(n + 1)]
 8     def find(self, x):
 9         i = x
10         while x != self.parent[x]:
11             x = self.parent[x]
12         self.parent[i] = x
13         return x
14     def union(self, x, y):
15         self.parent[self.find(x)] = self.find(y)
16 
17 class Solution(object):
18     def numberOfGoodPaths(self, vals, edges):
19         """
20         :type vals: List[int]
21         :type edges: List[List[int]]
22         :rtype: int
23         """
24         uf = UnionFind(len(vals))
25         node_val_set = defaultdict(set)
26         node_dict = defaultdict(list)
27         ans = len(vals)
28         for x, y in edges:
29             node_val_set[vals[x]].add(x)
30             node_val_set[vals[y]].add(y)
31             node_dict[x].append(y)
32             node_dict[y].append(x)
33         for i in sorted(node_val_set.keys()):
34             for j in node_val_set[i]:
35                 for k in node_dict[j]:
36                     if vals[k] <= i:
37                         uf.union(j, k)
38             cnt = defaultdict(int)
39             for j in node_val_set[i]:
40                 cnt[uf.find(j)] += 1
41             for r in cnt.keys():
42                 ans += (cnt[r] - 1) * cnt[r] // 2
43         return ans


Uriel 2023-01-15 21:24 鍙戣〃璇勮
]]>
[LeetCode]1061. Lexicographically Smallest Equivalent String (Medium) Python-2023.01.14http://www.shnenglu.com/Uriel/articles/229626.htmlUrielUrielSat, 14 Jan 2023 20:06:00 GMThttp://www.shnenglu.com/Uriel/articles/229626.htmlhttp://www.shnenglu.com/Uriel/comments/229626.htmlhttp://www.shnenglu.com/Uriel/articles/229626.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/229626.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/229626.html
Reflexivity: 'a' == 'a'.
Symmetry: 'a' == 'b' implies 'b' == 'a'.
Transitivity: 'a' == 'b' and 'b' == 'c' implies 'a' == 'c'.

鍙︾粰鍑轟竴涓猙aseStr錛岃緭鍑轟笌涔嬪絳夌殑瀛楃鎺掑簭鏈灝忕殑瀛楃涓?br />騫舵煡闆嗭紝灝唖1鍜宻2瀵瑰簲浣嶇疆鐨勫瓧絎︿竴涓騫跺叆鐩稿悓闆嗗悎錛屾敞鎰忓湪鍚堝茍鏃舵案榪滈夋嫨杈冨皬鐨勫瓧絎︿綔涓虹埗鑺傜偣

 1 #1061
 2 #Runtime: 26 ms (Beats 87.50%)
 3 #Memory: 13.5 MB (Beats 81.25%)
 4 
 5 class UnionFind:
 6     def __init__(self):
 7         self.parent = {}
 8     def find(self, x):
 9         if x not in self.parent:
10             self.parent[x] = x
11         i = x
12         while x != self.parent[x]:
13             x = self.parent[x]
14         self.parent[i] = x
15         return x
16     def union(self, x, y):
17         rx = self.find(x)
18         ry = self.find(y)
19         if rx > ry:
20             self.parent[rx] = ry
21         else:
22             self.parent[ry] = rx
23 
24 class Solution(object):
25     def smallestEquivalentString(self, s1, s2, baseStr):
26         """
27         :type s1: str
28         :type s2: str
29         :type baseStr: str
30         :rtype: str
31         """
32         uf = UnionFind()
33         for i in range(len(s1)):
34             uf.union(s1[i], s2[i])
35         ans = []
36         for c in baseStr:
37             ans.append(uf.find(c))        
38         return ''.join(ans)


Uriel 2023-01-15 04:06 鍙戣〃璇勮
]]>
[LeetCode]886. Possible Bipartition (Medium) Python-2022.12.21http://www.shnenglu.com/Uriel/articles/229580.htmlUrielUrielWed, 21 Dec 2022 08:18:00 GMThttp://www.shnenglu.com/Uriel/articles/229580.htmlhttp://www.shnenglu.com/Uriel/comments/229580.htmlhttp://www.shnenglu.com/Uriel/articles/229580.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/229580.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/229580.html騫舵煡闆嗭紝瀵逛簬姣忎釜id i錛岄澶勭悊鎵鏈変笉鑳藉拰浠栦竴緇勭殑ids錛岃繖浜沬ds灝嗕細琚垎鍦ㄤ竴緇勶紙騫舵煡闆唘nion鎿嶄綔錛夛紝濡傛灉鍙戠幇i鍜岃繖浜沬d鍦ㄥ茍鏌ラ泦鐨勫悓涓緇勶紝鍒欒緭鍑篎alse


 1 #886
 2 #Runtime: 2223 ms (Beats 5.11%)
 3 #Memory: 19.1 MB (Beats 72.26%)
 4 
 5 class UnionFind:
 6     def __init__(self, n):
 7         self.parent = [i for i in range(n + 1)]
 8     def find(self, x):
 9         i = x
10         while self.parent[x] != x:
11             x = self.parent[x]
12         self.parent[i] = x
13         return x
14     def union(self, x, y):
15         self.parent[self.find(x)] = self.find(y)
16 
17 
18 class Solution(object):
19     def possibleBipartition(self, n, dislikes):
20         """
21         :type n: int
22         :type dislikes: List[List[int]]
23         :rtype: bool
24         """
25         if n == 1:
26             return True
27         graph_dict = {}
28         for d in dislikes:
29             if d[0] not in graph_dict:
30                 graph_dict[d[0]] = [d[1]]
31             else:
32                 graph_dict[d[0]].append(d[1])
33             if d[1] not in graph_dict:
34                 graph_dict[d[1]] = [d[0]]
35             else:
36                 graph_dict[d[1]].append(d[0])
37         uf_set = UnionFind(n)
38         for x in graph_dict.keys():
39             for i in range(len(graph_dict[x]) - 1):
40                 uf_set.union(graph_dict[x][i], graph_dict[x][i + 1])
41             if uf_set.find(x) == uf_set.find(graph_dict[x][0]):
42                 return False
43         return True


Uriel 2022-12-21 16:18 鍙戣〃璇勮
]]>
[LeetCode]947. Most Stones Removed with Same Row or Column (Medium) Python-2022.11.14http://www.shnenglu.com/Uriel/articles/229517.htmlUrielUrielMon, 14 Nov 2022 11:48:00 GMThttp://www.shnenglu.com/Uriel/articles/229517.htmlhttp://www.shnenglu.com/Uriel/comments/229517.htmlhttp://www.shnenglu.com/Uriel/articles/229517.html#Feedback0http://www.shnenglu.com/Uriel/comments/commentRss/229517.htmlhttp://www.shnenglu.com/Uriel/services/trackbacks/229517.html
絎﹀悎鍚岃or鍚屽垪鐨勭煶瀛愰泦鍚堢粍鎴愪竴涓繛閫氬垎閲忥紝姣忎釜榪為氬垎閲忓彲浠ュ彧鐣欎笅涓棰楃煶瀛愶紙娌跨潃DFS璺緞涓璺幓鎺夌煶瀛愶級

鏂規硶涓錛欴FS姹傝繛閫氬垎閲忎釜鏁?br />
 1 #947
 2 #Runtime: 1060 ms
 3 #Memory Usage: 14.5 MB
 4 
 5 class Solution(object):
 6     def DFS(self, r, c):
 7         if len(self.dict_stones_row[r]) > 1:
 8             for j in self.dict_stones_row[r]:
 9                 if [r, j] not in self.vis:
10                     self.vis.append([r, j])
11                     self.DFS(r, j)
12         if len(self.dict_stones_col[c]) > 1:
13             for j in self.dict_stones_col[c]:
14                 if [j, c] not in self.vis:
15                     self.vis.append([j, c])
16                     self.DFS(j, c)
17         return
18     
19     def removeStones(self, stones):
20         """
21         :type stones: List[List[int]]
22         :rtype: int
23         """
24         self.dict_stones_row = {}
25         self.dict_stones_col = {}
26         self.vis = []
27         for i in stones:
28             if i[0] not in self.dict_stones_row:
29                 self.dict_stones_row[i[0]] = []
30             self.dict_stones_row[i[0]].append(i[1])
31             if i[1] not in self.dict_stones_col:
32                 self.dict_stones_col[i[1]] = []
33             self.dict_stones_col[i[1]].append(i[0])
34         nc = 0
35         for i in stones:
36             if i not in self.vis:
37                 self.DFS(i[0], i[1])
38                 nc += 1
39         return len(stones) - nc

鏂規硶浜岋細騫舵煡闆嗭紝鏄疍FS鐨勫嚑涔?鍊嶉熷害錛岀湅Discussion鑾峰緱鐨勬濊礬錛屽皬鎶宸ф槸鍙互灝嗙旱鍧愭爣i鐢▇i鎿嶄綔杞寲涓哄拰妯潗鏍囨棤overlap鐨勫鹼紝榪欐牱鍙互濉炶繘涓涓茍鏌ラ泦緇熶竴澶勭悊榪欎釜騫舵煡闆嗗啓娉曚篃寰堢畝媧?br />
 1 #947
 2 #Runtime: 129 ms
 3 #Memory Usage: 14.1 MB
 4 
 5 class Solution(object):
 6     def find(self, x):
 7         if x != self.uf.setdefault(x, x):
 8             self.uf[x] = self.find(self.uf[x])
 9         return self.uf[x]
10     
11     def removeStones(self, stones):
12         """
13         :type stones: List[List[int]]
14         :rtype: int
15         """
16         self.uf = {}
17         for i, j in stones:
18             self.uf[self.find(i)] = self.find(~j)
19         return len(stones) - len({self.find(x) for x in self.uf})


Uriel 2022-11-14 19:48 鍙戣〃璇勮
]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            夜夜嗨av一区二区三区网站四季av | 亚洲综合欧美日韩| 亚洲视频一起| 依依成人综合视频| 亚洲精品在线视频观看| 亚洲激情欧美激情| 亚洲一区二区成人在线观看| 亚洲第一精品夜夜躁人人躁| 亚洲欧美在线一区二区| 亚洲欧洲精品一区二区| 亚洲专区一区| 一区二区三区国产在线| 欧美电影免费| 久久亚洲欧美| 国产精品一二三视频| 日韩视频二区| 亚洲国产精品一区二区第一页| 亚洲一区二区欧美日韩| 精品动漫一区二区| 亚洲欧美日韩精品久久奇米色影视| 亚洲精品永久免费| 久久人人97超碰国产公开结果| 欧美影院在线| 欧美日韩中文字幕精品| 亚洲国产精品ⅴa在线观看 | 曰韩精品一区二区| 在线视频免费在线观看一区二区| 亚洲激情另类| 欧美韩日精品| 亚洲国产精品ⅴa在线观看| 国内激情久久| 久久久久综合| 久久久久九九九| 国产精品一区二区女厕厕| 亚洲国产精品电影| 99精品欧美一区二区蜜桃免费| 久久亚洲国产成人| 久久久久国产精品一区| 亚洲第一二三四五区| 久久成人在线| 久久天天躁狠狠躁夜夜爽蜜月| 欧美激情一区二区三区不卡| 欧美不卡一卡二卡免费版| 国产一区再线| 久久不见久久见免费视频1| 久久成人精品电影| 国产情人综合久久777777| 欧美在线观看你懂的| 久久久久中文| 一区二区在线观看视频在线观看| 久热国产精品视频| 久久久999成人| 激情国产一区二区| 欧美一级成年大片在线观看| 久久免费国产精品1| 国产日韩欧美一二三区| 欧美一区二区三区喷汁尤物| 香蕉久久久久久久av网站| 国产精品一区二区三区四区| 在线亚洲成人| 久久精品国产成人| 好看的日韩视频| 欧美亚洲免费在线| 最新成人在线| 亚洲专区一二三| 国产亚洲成精品久久| 欧美激情网站在线观看| 一本色道88久久加勒比精品 | 海角社区69精品视频| 你懂的国产精品| 一个人看的www久久| 久久精品欧美日韩精品| 亚洲美女精品成人在线视频| 欧美日韩亚洲一区二区| 亚洲在线不卡| 亚洲精品国产精品乱码不99 | 性久久久久久久久| 国产专区欧美精品| 欧美高清一区二区| 亚洲欧美国产高清| 亚洲美女视频网| 欧美资源在线观看| 亚洲精品色婷婷福利天堂| 国产一区二区三区久久悠悠色av| 欧美电影打屁股sp| 午夜精彩视频在线观看不卡| 亚洲精品久久在线| 美女成人午夜| 99国产一区二区三精品乱码| 伊人久久婷婷| 国产精品爽黄69| 久久久久一区二区三区| 午夜综合激情| 99精品视频一区| 欧美大香线蕉线伊人久久国产精品| 久久精品噜噜噜成人av农村| 中日韩男男gay无套| 国产亚洲欧美日韩美女| 国产精品xvideos88| 六月丁香综合| 欧美在线亚洲综合一区| 亚洲小视频在线观看| 亚洲欧洲日本在线| 麻豆精品91| av成人毛片| 99re在线精品| 亚洲欧洲日本专区| 国产一区二区三区在线观看网站 | 国产偷国产偷精品高清尤物| 欧美区一区二区三区| 欧美成人xxx| 麻豆91精品91久久久的内涵| 亚洲一区日本| 欧美激情一区二区三区在线视频观看| 久久欧美中文字幕| 午夜精品久久久久久99热| 99国产精品久久| 99这里只有久久精品视频| 91久久夜色精品国产九色| 狠狠色丁香久久婷婷综合丁香| 欧美性片在线观看| 国产精品久久久久久久久婷婷| 欧美精品福利视频| 欧美日韩免费看| 国产精品国产三级国产a| 国产精品成人观看视频免费| 欧美亚日韩国产aⅴ精品中极品| 久久夜色精品| 免播放器亚洲| 欧美激情精品久久久久久免费印度| 亚久久调教视频| 免费视频一区| 免费在线成人av| 美玉足脚交一区二区三区图片| 欧美日本不卡视频| 欧美日本不卡| 国产精品久久久久一区二区三区共 | 日韩午夜剧场| 亚洲专区国产精品| 久久影视精品| 欧美视频一区二区在线观看| 国产亚洲欧美另类中文| 亚洲国产老妈| 香蕉久久精品日日躁夜夜躁| 免费成人在线观看视频| 日韩亚洲欧美成人| 欧美自拍偷拍午夜视频| 欧美激情综合在线| 国产一区二区三区不卡在线观看| 亚洲精品欧美日韩专区| 久久国产免费看| 91久久嫩草影院一区二区| 亚洲一区二区成人| 欧美成人免费播放| 国产一区二区三区日韩| 亚洲视频日本| 欧美不卡三区| 香蕉久久国产| 国产精品jizz在线观看美国| 亚洲国产精品视频一区| 午夜精品视频在线观看| 91久久午夜| 久久青草欧美一区二区三区| 国产精品进线69影院| 亚洲黄色视屏| 久久久另类综合| aaa亚洲精品一二三区| 久久综合久久88| 国产午夜亚洲精品不卡| 在线综合欧美| 亚洲第一天堂无码专区| 欧美在线视频导航| 国产精品久久久久三级| 亚洲免费高清| 亚洲高清自拍| 久热re这里精品视频在线6| 国产一区二区久久| 欧美一区二区三区喷汁尤物| 99精品国产在热久久| 欧美激情91| 最新成人av在线| 欧美va亚洲va香蕉在线| 欧美一区二区三区视频在线观看| 国产精品久久网站| 亚洲一区www| 99pao成人国产永久免费视频| 欧美国产第一页| 亚洲精选在线观看| 亚洲欧洲精品一区二区精品久久久| 久久综合一区| 亚洲精华国产欧美| 欧美激情免费在线| 噜噜噜噜噜久久久久久91| 亚洲国产精品999| 欧美顶级少妇做爰| 欧美国产激情二区三区| 一本色道久久综合亚洲精品高清 | 亚洲免费一级电影| 国产精品资源在线观看| 欧美伊人影院|