• <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
            97精品国产97久久久久久免费 | 国产精品一区二区久久精品涩爱 | 久久久久久久综合狠狠综合| 亚洲精品第一综合99久久| 久久无码专区国产精品发布 | 久久婷婷五月综合97色| 久久精品成人免费看| 亚洲欧美日韩精品久久亚洲区| 久久精品亚洲AV久久久无码| 狠狠狠色丁香婷婷综合久久俺| 色欲综合久久躁天天躁| 久久99精品国产99久久6男男| 亚洲性久久久影院| 91久久精品视频| 久久精品卫校国产小美女| 精品国产婷婷久久久| 久久久无码人妻精品无码| 伊人伊成久久人综合网777| 久久免费线看线看| 久久精品国产精品亚洲毛片| 蜜桃麻豆WWW久久囤产精品| 久久久久人妻精品一区三寸蜜桃| 国产一级做a爰片久久毛片| 亚洲AV无码久久精品狠狠爱浪潮| 久久这里只有精品视频99| 国产激情久久久久影院小草| 久久久噜噜噜久久中文福利| 久久久高清免费视频| 久久亚洲中文字幕精品一区| 99久久精品国产毛片| segui久久国产精品| 99久久精品免费看国产免费| 99精品久久精品一区二区| 久久久久久久久久久| 欧美激情精品久久久久久久| 成人国内精品久久久久影院VR| 狠狠色噜噜狠狠狠狠狠色综合久久 | 国产一区二区三精品久久久无广告| 久久免费精品一区二区| 亚洲国产二区三区久久| 久久996热精品xxxx|