• <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
            国产精品美女久久久久av爽| 日本高清无卡码一区二区久久| 波多野结衣AV无码久久一区| 精品国产青草久久久久福利| 国产婷婷成人久久Av免费高清| 996久久国产精品线观看| 国产免费福利体检区久久 | 久久精品国产99国产精偷| 国产伊人久久| 97久久香蕉国产线看观看| 久久无码一区二区三区少妇| 久久精品国产亚洲精品2020| 四虎影视久久久免费观看| 久久99国产亚洲高清观看首页| 深夜久久AAAAA级毛片免费看| 99久久精品国产高清一区二区| 久久国产成人午夜aⅴ影院| 久久久久亚洲AV片无码下载蜜桃| 久久久久久久国产免费看| 91精品国产综合久久久久久| 一本久久综合亚洲鲁鲁五月天| 欧美777精品久久久久网| 亚洲国产美女精品久久久久∴| 久久久噜噜噜久久| 国产精品亚洲美女久久久| 久久精品国产亚洲一区二区| AV无码久久久久不卡蜜桃| 亚洲成av人片不卡无码久久| 九九热久久免费视频| 国产精品热久久毛片| 国内精品伊人久久久久网站| 色综合久久最新中文字幕| 久久久久久狠狠丁香| 99久久免费国产精品| 99久久精品九九亚洲精品| 91精品国产综合久久香蕉| 久久久久综合网久久| 久久精品免费一区二区三区| 国产精品美女久久久久| 久久精品国产秦先生| 久久免费视频观看|