• <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
            久久国产精品久久精品国产| 综合网日日天干夜夜久久 | 亚洲人成无码www久久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 精品欧美一区二区三区久久久| 热久久国产精品| 亚洲精品国精品久久99热| avtt天堂网久久精品| 久久一本综合| 久久国产精品一区二区| 色综合久久夜色精品国产| 99久久免费国产精品热| 免费久久人人爽人人爽av| 久久香蕉国产线看观看99| 久久国内免费视频| 久久久久99精品成人片 | 久久亚洲色一区二区三区| 日韩人妻无码精品久久久不卡| 国产成人99久久亚洲综合精品| 久久精品夜夜夜夜夜久久| 中文成人久久久久影院免费观看| 久久久久久a亚洲欧洲aⅴ| 亚洲精品国产字幕久久不卡| 欧美日韩精品久久久久| 热99re久久国超精品首页| 国产精品禁18久久久夂久| 色妞色综合久久夜夜| 久久久无码精品亚洲日韩蜜臀浪潮| 99久久综合狠狠综合久久| 99久久久精品| 久久婷婷久久一区二区三区| 久久精品天天中文字幕人妻| 亚洲色大成网站WWW久久九九| 久久亚洲电影| 午夜视频久久久久一区| 久久精品国产WWW456C0M| 久久久国产精品| 久久精品国产欧美日韩99热| 久久99热这里只有精品66| 少妇人妻88久久中文字幕| 久久亚洲私人国产精品vA|