• <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
            給定一個有向圖,和其中每個節(jié)點的顏色,問其中的所有path中經(jīng)過同色最多的節(jié)點的個數(shù),DFS劃水過了
            *有部分參考->https://leetcode.com/problems/largest-color-value-in-a-directed-graph/solutions/3396323/


             1 #1857
             2 #Runtime: 3256 ms (Beats 12.50%)
             3 #Memory: 202.1 MB (Beats 12.50%)
             4 
             5 class Solution(object):
             6     def largestPathValue(self, colors, edges):
             7         """
             8         :type colors: str
             9         :type edges: List[List[int]]
            10         :rtype: int
            11         """
            12         graph = defaultdict(list)
            13         for x, y in edges:
            14             graph[x].append(y)
            15         vis = set()
            16         path = set()
            17         ans = 0
            18         n = len(colors)
            19         self.has_circle = False
            20         cnt = [[0] * 26 for _ in range(n)]
            21         def DFS(x):
            22             if x in path:
            23                 self.has_circle = True
            24             if x in vis:
            25                 return 0
            26             vis.add(x)
            27             path.add(x)
            28             idx = ord(colors[x]) - ord('a')
            29             cnt[x][idx] = 1
            30             for y in graph[x]:
            31                 DFS(y)
            32                 if self.has_circle == True:
            33                     return float('inf')
            34                 for ch in range(26):
            35                     cnt[x][ch] = max(cnt[x][ch], (1 if ch == idx else 0) + cnt[y][ch])
            36             path.remove(x)
            37             return max(cnt[x])
            38 
            39         for i in range(n):
            40             ans = max(ans, DFS(i))
            41         return -1 if ans == float('inf'else ans
            久久91综合国产91久久精品| 久久精品aⅴ无码中文字字幕不卡| 亚洲国产综合久久天堂 | 久久受www免费人成_看片中文| AV狠狠色丁香婷婷综合久久| 久久无码人妻一区二区三区| 伊人久久大香线蕉av不卡| 久久国产劲爆AV内射—百度| 成人午夜精品无码区久久| 久久综合给久久狠狠97色| 久久精品国产99久久无毒不卡 | 一本色道久久88综合日韩精品 | 精品久久久久久久久久久久久久久 | 2021精品国产综合久久| av无码久久久久久不卡网站 | 热综合一本伊人久久精品| 久久久亚洲精品蜜桃臀| 久久亚洲日韩看片无码| 男女久久久国产一区二区三区| 97超级碰碰碰久久久久| 国产毛片久久久久久国产毛片 | 久久久久亚洲AV成人片| 国产欧美一区二区久久| 精品久久久久久国产牛牛app| 无码八A片人妻少妇久久| 久久久噜噜噜久久熟女AA片| 色成年激情久久综合| 欧美午夜A∨大片久久| 久久人人爽人人爽人人片av高请| 久久99国产精品久久| 色狠狠久久综合网| 久久久久四虎国产精品| 四虎国产精品成人免费久久| 久久精品视频网| 狠狠色噜噜色狠狠狠综合久久| 久久国产免费观看精品| 热久久最新网站获取| 91精品国产综合久久四虎久久无码一级 | 国产aⅴ激情无码久久| 精品久久人人妻人人做精品| 午夜天堂精品久久久久|