2077. Paths in Maze That Lead to Same Room

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2077

class Solution:
    def numberOfPaths(self, n: int, corridors: List[List[int]]) -> int:
        g = defaultdict(set)
        for a, b in corridors:
            g[a].add(b)
            g[b].add(a)
        res = 0
        for i in range(1, n + 1):
            for j, k in combinations(g[i], 2):
                if j in g[k]:
                    res += 1
        return res // 3