• <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>

            Uriel's Corner

            Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
            posts - 0, comments - 50, trackbacks - 0, articles - 594
            找出無向圖最小生成樹的關鍵邊和偽關鍵邊

            定義:
            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]
            久久亚洲精品视频| 人妻无码αv中文字幕久久琪琪布| 久久丫精品国产亚洲av| 韩国免费A级毛片久久| 国产综合免费精品久久久| 久久久噜噜噜久久中文字幕色伊伊| 丰满少妇高潮惨叫久久久| 国产一级做a爰片久久毛片| 亚洲国产天堂久久综合| 国产成人精品久久免费动漫| 婷婷久久综合九色综合九七| 久久九九精品99国产精品| 久久亚洲中文字幕精品一区| 久久久噜噜噜久久熟女AA片| 99久久做夜夜爱天天做精品| 人人狠狠综合久久亚洲婷婷| 久久人人爽人人爽人人AV| 久久久久97国产精华液好用吗| 久久夜色精品国产网站| 久久国产精品无| 欧美久久久久久午夜精品| 91精品婷婷国产综合久久| 久久国产精品成人影院| 久久夜色精品国产亚洲| 无码乱码观看精品久久| 亚洲国产小视频精品久久久三级 | 久久国产成人精品麻豆| 久久成人国产精品免费软件| 思思久久99热只有频精品66| 亚洲国产天堂久久综合| 午夜精品久久久久成人| 欧美性猛交xxxx免费看久久久| 免费精品久久久久久中文字幕 | 久久亚洲春色中文字幕久久久| 伊人久久大香线蕉无码麻豆 | 99久久国产综合精品女同图片| 亚洲乱码日产精品a级毛片久久| 久久国产午夜精品一区二区三区| 久久久久国产精品麻豆AR影院| 久久精品夜色噜噜亚洲A∨| 久久影院久久香蕉国产线看观看|