Python in 10 lines, Dijkstra
IntuitionImagine all ugly numbers as a directed graph, where each number leads to several others by multiplying each of the primes. The goal is the find nth sma
# Intuition
Imagine all ugly numbers as a directed graph, where each number leads to several others by multiplying each of the primes. The goal is the find nth smallest node, which shares similarity with shortest distance in a graph problem.

# Approach
Dijkstra

# Complexity
- Time complexity:
$$O(n)$$

- Space complexity:
$$O(V)$$

# Code
```python3 []
import heapq as q

class Solution:
    def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int:
        queue, visited, x, i = [1], set(), None, 0
        while i < n:
            x = q.heappop(queue)
            if x in visited:
                continue
            visited.add(x)
            i += 1
            for p in primes:
                q.heappush(queue, x * p)
        return x

```
['Python3']