• <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
            給出一個無向圖最多100000個節點,每條邊給出相應的距離,有最多100000次詢問,每次詢問x和y節點之間是否存在一條路,路上所有邊的距離都小于(不包含等于)limit。并查集的應用,在合并和查找時增加對dis的維護和判斷


             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
            天天爽天天爽天天片a久久网| 国内精品久久久久久麻豆 | 国产成人综合久久久久久| 国产精品久久久亚洲| 99久久这里只有精品| 久久免费精品视频| 久久青青草原亚洲av无码| 亚洲精品无码久久不卡| 亚洲AV无码久久精品色欲 | 久久国产精品99久久久久久老狼 | 国产福利电影一区二区三区久久久久成人精品综合 | 久久这里都是精品| 久久精品中文字幕无码绿巨人| 亚洲国产成人久久综合碰碰动漫3d| 国产免费福利体检区久久| 久久久久人妻一区二区三区| 久久99国产精品99久久| 亚洲欧洲中文日韩久久AV乱码| 久久久国产乱子伦精品作者| 久久久无码精品午夜| 久久亚洲私人国产精品| 久久精品国产亚洲Aⅴ蜜臀色欲| 精品久久久无码人妻中文字幕| 91久久精品视频| 亚洲综合精品香蕉久久网| 国产精品成人99久久久久| 亚洲AV无码久久精品色欲| 亚洲欧美久久久久9999| 99久久免费国产精品| 色综合久久无码中文字幕| 久久亚洲电影| 99久久国产主播综合精品| 97久久超碰国产精品旧版| 97久久国产综合精品女不卡| 亚洲精品乱码久久久久久不卡| 91精品国产91久久久久久青草| 久久久久亚洲AV无码专区体验| A级毛片无码久久精品免费| 亚洲欧美另类日本久久国产真实乱对白| 久久国产高清字幕中文| 狠狠色丁香久久婷婷综|