[LeetCode] 1976. Number of Ways to Arrive at Destination (Python)
·
알고리즘/LeetCode
난이도: MediumProblem Description You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections. You are given an integer n and a 2D integer array roads where roads[i] = [ui,..
[LeetCode] 3108. Minimum Cost Walk in Weighted Graph (Python)
·
알고리즘/LeetCode
난이도: HardProblem DescriptionThere is an undirected weighted graph with n vertices labeled from 0 to n - 1. You are given the integer n and an array edges, where edges[i] = [ui, vi, wi] indicates that there is an edge between vertices ui and vi with a weight of wi. A walk on a graph is a sequence of vertices and edges. The walk starts and ends with a vertex, and each edge connects the vertex that..
[LeetCode] 2467. Most Profitable Path in a Tree (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. At every node i, there is a gate. You are also given an array of even integers amount, where amount[i] represents:the price needed to open the gate ..
[LeetCode] 2658. Maximum Number of Fish in a Grid (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents:A land cell if grid[r][c] = 0, orA water cell containing grid[r][c] fish, if grid[r][c] > 0.A fisher can start at any water cell (r, c) and can do the following operations any number of times:Catch all the fish at cell (r, c), orMove to any adjacent water cell.Return the maximum number of fish the fis..
[LeetCode] 1462. Course Schedule IV (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명 There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course ai first if you want to take course bi.For example, the pair [0, 1] indicates that you have to take course 0 before you can take course 1.Prerequisites can also be indirect. If cours..
[LeetCode] 802. Find Eventual Safe States (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명There is a directed graph of n nodes with each node labeled from 0 to n - 1. The graph is represented by a 0-indexed 2D integer array graph where graph[i] is an integer array of nodes adjacent to node i, meaning there is an edge from node i to each node in graph[i]. A node is a terminal node if there are no outgoing edges. A node is a safe node if every possible path starting fro..