• <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
            給定一個有向圖,和其中每個節點的顏色,問其中的所有path中經過同色最多的節點的個數,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
            久久无码中文字幕东京热| 久久综合中文字幕| 无码乱码观看精品久久| 国产成人综合久久久久久| 国产呻吟久久久久久久92| 久久国产视频网| A级毛片无码久久精品免费| 久久久久亚洲AV无码麻豆| 精品久久久久久久无码| 亚洲国产成人久久精品动漫| 精品国产日韩久久亚洲| 亚洲日韩中文无码久久| 国产精品免费久久久久电影网| 久久热这里只有精品在线观看| 日韩一区二区久久久久久 | 99久久国产宗和精品1上映| 国产精品欧美久久久天天影视| 久久精品成人影院| 亚洲午夜久久久久久久久电影网 | 精品久久人人爽天天玩人人妻| 久久精品国产清自在天天线| 久久青青草原精品影院| 香蕉久久av一区二区三区| 久久五月精品中文字幕| 久久精品国产一区二区| 久久99亚洲网美利坚合众国| 久久精品中文无码资源站| 久久精品无码一区二区WWW| 精品久久久久久国产免费了| 久久99精品国产麻豆蜜芽| 77777亚洲午夜久久多喷| 日韩精品久久久久久免费| 模特私拍国产精品久久| 久久黄视频| 久久久噜噜噜久久中文字幕色伊伊| 久久精品一区二区| 99精品伊人久久久大香线蕉| 亚洲一区中文字幕久久| 久久精品视屏| 久久国产欧美日韩精品| 久久夜色精品国产网站|