leetcode.cn 2023-12-06
🔴2646.minimize-the-total-price-of-the-trips
🏷️ Tags
#tree #depth_first_search #graph #array #dynamic_programming
🔴2646.minimize-the-total-price-of-the-trips
🏷️ Tags
#tree #depth_first_search #graph #array #dynamic_programming
Telegraph
minimize-the-total-price-of-the-trips
现有一棵无向、无根的树,树中有 n 个节点,按从 0 到 n - 1 编号。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ,其中 edges[i] = [ai, bi] 表示树中节点 ai 和 bi 之间存在一条边。 每个节点都关联一个价格。给你一个整数数组 price ,其中 price[i] 是第 i 个节点的价格。 给定路径的 价格总和 是该路径上所有节点的价格之和。 另给你一个二维整数数组 trips ,其中 trips[i] = [starti, endi] 表示您从节点…
leetcode.cn 2023-12-07
🟡1466.reorder-routes-to-make-all-paths-lead-to-the-city-zero
🏷️ Tags
#depth_first_search #breadth_first_search #graph
🟡1466.reorder-routes-to-make-all-paths-lead-to-the-city-zero
🏷️ Tags
#depth_first_search #breadth_first_search #graph
Telegraph
reorder-routes-to-make-all-paths-lead-to-the-city-zero
n 座城市,从 0 到 n-1 编号,其间共有 n-1 条路线。因此,要想在两座不同城市之间旅行只有唯一一条路线可供选择(路线网形成一颗树)。去年,交通运输部决定重新规划路线,以改变交通拥堵的状况。 路线用 connections 表示,其中 connections[i] = [a, b] 表示从城市 a 到 b 的一条有向路线。 今年,城市 0 将会举办一场大型比赛,很多游客都想前往城市 0 。 请你帮助重新规划路线方向,使每个城市都可以访问城市 0 。返回需要变更方向的最小路线数。 题目数据 保证 …
leetcode.cn 2024-01-26
🔴2846.minimum-edge-weight-equilibrium-queries-in-a-tree
🏷️ Tags
#tree #graph #array #strongly_connected_component
🔴2846.minimum-edge-weight-equilibrium-queries-in-a-tree
🏷️ Tags
#tree #graph #array #strongly_connected_component
Telegraph
minimum-edge-weight-equilibrium-queries-in-a-tree
现有一棵由 n 个节点组成的无向树,节点按从 0 到 n - 1 编号。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ,其中 edges[i] = [ui, vi, wi] 表示树中存在一条位于节点 ui 和节点 vi 之间、权重为 wi 的边。 另给你一个长度为 m 的二维整数数组 queries ,其中 queries[i] = [ai, bi] 。对于每条查询,请你找出使从 ai 到 bi 路径上每条边的权重相等所需的 最小操作次数 。在一次操作中,你可以选择树上的任意一条边,并将其权重更改为任意值。…
leetcode.com 2025-02-24
🟡2467.most-profitable-path-in-a-tree
🏷️ Tags
#tree #depth_first_search #breadth_first_search #graph #array
🟡2467.most-profitable-path-in-a-tree
🏷️ Tags
#tree #depth_first_search #breadth_first_search #graph #array
Telegraph
most-profitable-path-in-a-tree
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…
leetcode.com 2025-03-20
🔴3108.minimum-cost-walk-in-weighted-graph
🏷️ Tags
#bit_manipulation #union_find #graph #array
🔴3108.minimum-cost-walk-in-weighted-graph
🏷️ Tags
#bit_manipulation #union_find #graph #array
Telegraph
minimum-cost-walk-in-weighted-graph
There 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…
👍1
leetcode.com 2025-03-21
🟡2115.find-all-possible-recipes-from-given-supplies
🏷️ Tags
#graph #topological_sort #array #hash_table #string
🟡2115.find-all-possible-recipes-from-given-supplies
🏷️ Tags
#graph #topological_sort #array #hash_table #string
Telegraph
find-all-possible-recipes-from-given-supplies
You have information about n different recipes. You are given a string array recipes and a 2D string array ingredients. The ith recipe has the name recipes[i], and you can create it if you have all the needed ingredients from ingredients[i]. A recipe can…
leetcode.com 2025-03-22
🟡2685.count-the-number-of-complete-components
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph
🟡2685.count-the-number-of-complete-components
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph
Telegraph
count-the-number-of-complete-components
You are given an integer n. There is an undirected graph with n vertices, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] = [ai, bi] denotes that there exists an undirected edge connecting vertices ai and bi. Return the number…
leetcode.cn 2025-03-29
🔴2360.longest-cycle-in-a-graph
🏷️ Tags
#depth_first_search #breadth_first_search #graph #topological_sort
🔴2360.longest-cycle-in-a-graph
🏷️ Tags
#depth_first_search #breadth_first_search #graph #topological_sort
Telegraph
longest-cycle-in-a-graph
给你一个 n 个节点的 有向图 ,节点编号为 0 到 n - 1 ,其中每个节点 至多 有一条出边。 图用一个大小为 n 下标从 0 开始的数组 edges 表示,节点 i 到节点 edges[i] 之间有一条有向边。如果节点 i 没有出边,那么 edges[i] == -1 。 请你返回图中的 最长 环,如果没有任何环,请返回 -1 。 一个环指的是起点和终点是 同一个 节点的路径。 示例 1: 输入:edges = [3,3,4,2,3] 输出去:3 解释:图中的最长环是:2 -> 4 -> 3…
leetcode.cn 2025-05-07
🟡3341.find-minimum-time-to-reach-last-room-i
🏷️ Tags
#graph #array #matrix #shortest_path #heap_priority_queue
🟡3341.find-minimum-time-to-reach-last-room-i
🏷️ Tags
#graph #array #matrix #shortest_path #heap_priority_queue
Telegraph
find-minimum-time-to-reach-last-room-i
有一个地窖,地窖中有 n x m 个房间,它们呈网格状排布。 给你一个大小为 n x m 的二维数组 moveTime ,其中 moveTime[i][j] 表示在这个时刻 以后 你才可以 开始 往这个房间 移动 。你在时刻 t = 0 时从房间 (0, 0) 出发,每次可以移动到 相邻 的一个房间。在 相邻 房间之间移动需要的时间为 1 秒。
leetcode.com 2025-05-07
🟡3341.find-minimum-time-to-reach-last-room-i
🏷️ Tags
#graph #array #matrix #shortest_path #heap_priority_queue
🟡3341.find-minimum-time-to-reach-last-room-i
🏷️ Tags
#graph #array #matrix #shortest_path #heap_priority_queue
Telegraph
find-minimum-time-to-reach-last-room-i
There is a dungeon with n x m rooms arranged as a grid. You are given a 2D array moveTime of size n x m, where moveTime[i][j] represents the minimum time in seconds when you can start moving to that room. You start from the room (0, 0) at time t = 0 and can…
leetcode.cn 2025-05-08
🟡3342.find-minimum-time-to-reach-last-room-ii
🏷️ Tags
#graph #array #matrix #shortest_path #heap_priority_queue
🟡3342.find-minimum-time-to-reach-last-room-ii
🏷️ Tags
#graph #array #matrix #shortest_path #heap_priority_queue
Telegraph
find-minimum-time-to-reach-last-room-ii
有一个地窖,地窖中有 n x m 个房间,它们呈网格状排布。 给你一个大小为 n x m 的二维数组 moveTime ,其中 moveTime[i][j] 表示在这个时刻 以后 你才可以 开始 往这个房间 移动 。你在时刻 t = 0 时从房间 (0, 0) 出发,每次可以移动到 相邻 的一个房间。在 相邻 房间之间移动需要的时间为:第一次花费 1 秒,第二次花费 2 秒,第三次花费 1 秒,第四次花费 2 秒……如此 往复 。