Leetcode-cn.com 2022-01-24
🔴 2045.second-minimum-time-to-reach-destination
🏷️ Tags
#breadth_first_search #graph #shortest_path
Description
城市用一个 双向连通 图表示,图中有
每个节点都有一个交通信号灯,每
第二小的值 是 严格大于 最小值的所有值中最小的值。
例如,
给你
注意:
你可以 任意次 穿过任意顶点,包括
你可以假设在 启程时 ,所有信号灯刚刚变成 绿色 。
Example
🔴 2045.second-minimum-time-to-reach-destination
🏷️ Tags
#breadth_first_search #graph #shortest_path
Description
城市用一个 双向连通 图表示,图中有
n 个节点,从 1 到 n 编号(包含 1 和 n)。图中的边用一个二维整数数组 edges 表示,其中每个 edges[i] = [ui, vi] 表示一条节点 ui 和节点 vi 之间的双向连通边。每组节点对由 最多一条 边连通,顶点不存在连接到自身的边。穿过任意一条边的时间是 time 分钟。每个节点都有一个交通信号灯,每
change 分钟改变一次,从绿色变成红色,再由红色变成绿色,循环往复。所有信号灯都 同时 改变。你可以在 任何时候 进入某个节点,但是 只能 在节点 信号灯是绿色时 才能离开。如果信号灯是 绿色 ,你 不能 在节点等待,必须离开。第二小的值 是 严格大于 最小值的所有值中最小的值。
例如,
[2, 3, 4] 中第二小的值是 3 ,而 [2, 2, 4] 中第二小的值是 4 。给你
n、edges、time 和 change ,返回从节点 1 到节点 n 需要的 第二短时间 。注意:
你可以 任意次 穿过任意顶点,包括
1 和 n 。你可以假设在 启程时 ,所有信号灯刚刚变成 绿色 。
Example
输入:n = 5, edges = [[1,2],[1,3],[1,4],[3,4],[4,5]], time = 3, change = 5
输出:13
解释:
上面的左图展现了给出的城市交通图。
右图中的蓝色路径是最短时间路径。
花费的时间是:
- 从节点 1 开始,总花费时间=0
- 1 -> 4:3 分钟,总花费时间=3
- 4 -> 5:3 分钟,总花费时间=6
因此需要的最小时间是 6 分钟。
右图中的红色路径是第二短时间路径。
- 从节点 1 开始,总花费时间=0
- 1 -> 3:3 分钟,总花费时间=3
- 3 -> 4:3 分钟,总花费时间=6
- 在节点 4 等待 4 分钟,总花费时间=10
- 4 -> 5:3 分钟,总花费时间=13
因此第二短时间是 13 分钟。
882.reachable-nodes-in-subdivided-graph.pdf
220 KB
leetcode.cn 2022-11-26
🔴882.reachable-nodes-in-subdivided-graph
🏷️ Tags
#graph #shortest_path #heap_priority_queue
🔴882.reachable-nodes-in-subdivided-graph
🏷️ Tags
#graph #shortest_path #heap_priority_queue
787.cheapest-flights-within-k-stops.pdf
108.5 KB
leetcode.com 2023-01-26
🟡787.cheapest-flights-within-k-stops
🏷️ Tags
#dynamic_programming #depth_first_search #breadth_first_search #graph #heap_priority_queue #shortest_path
🟡787.cheapest-flights-within-k-stops
🏷️ Tags
#dynamic_programming #depth_first_search #breadth_first_search #graph #heap_priority_queue #shortest_path
leetcode.com 2023-05-20
🟡399.evaluate-division
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph #array #shortest_path
🟡399.evaluate-division
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #graph #array #shortest_path
Telegraph
evaluate-division
You are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equation Ai / Bi = values[i]. Each Ai or Bi is a string that represents a single variable. You are also given…
leetcode.cn 2023-06-04
🔴2699.modify-graph-edge-weights
🏷️ Tags
#graph #shortest_path #heap_priority_queue
🔴2699.modify-graph-edge-weights
🏷️ Tags
#graph #shortest_path #heap_priority_queue
Telegraph
modify-graph-edge-weights
给你一个 n 个节点的 无向带权连通 图,节点编号为 0 到 n - 1 ,再给你一个整数数组 edges ,其中 edges[i] = [ai, bi, wi] 表示节点 ai 和 bi 之间有一条边权为 wi 的边。 部分边的边权为 -1(wi = -1),其他边的边权都为 正 数(wi > 0)。 你需要将所有边权为 -1 的边都修改为范围 [1, 2 * 109] 中的 正整数 ,使得从节点 source 到节点 destination 的 最短距离 为整数 target 。如果有 多种 修改方案可以使 source…
leetcode.cn 2023-06-09
🔴2699.modify-graph-edge-weights
🏷️ Tags
#graph #shortest_path #heap_priority_queue
🔴2699.modify-graph-edge-weights
🏷️ Tags
#graph #shortest_path #heap_priority_queue
Telegraph
modify-graph-edge-weights
给你一个 n 个节点的 无向带权连通 图,节点编号为 0 到 n - 1 ,再给你一个整数数组 edges ,其中 edges[i] = [ai, bi, wi] 表示节点 ai 和 bi 之间有一条边权为 wi 的边。 部分边的边权为 -1(wi = -1),其他边的边权都为 正 数(wi > 0)。 你需要将所有边权为 -1 的边都修改为范围 [1, 2 * 109] 中的 正整数 ,使得从节点 source 到节点 destination 的 最短距离 为整数 target 。如果有 多种 修改方案可以使 source…
leetcode.com 2023-06-28
🟡1514.path-with-maximum-probability
🏷️ Tags
#graph #array #shortest_path #heap_priority_queue
🟡1514.path-with-maximum-probability
🏷️ Tags
#graph #array #shortest_path #heap_priority_queue
Telegraph
path-with-maximum-probability
You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with a probability of success of traversing that edge succProb[i]. Given two nodes start and end…
leetcode.com 2023-11-11
🔴2642.design-graph-with-shortest-path-calculator
🏷️ Tags
#graph #design #shortest_path #heap_priority_queue
🔴2642.design-graph-with-shortest-path-calculator
🏷️ Tags
#graph #design #shortest_path #heap_priority_queue
Telegraph
design-graph-with-shortest-path-calculator
There is a directed weighted graph that consists of n nodes numbered from 0 to n - 1. The edges of the graph are initially represented by the given array edges where edges[i] = [fromi, toi, edgeCosti] meaning that there is an edge from fromi to toi with the…
leetcode.cn 2023-11-14
🟡1334.find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
🏷️ Tags
#graph #dynamic_programming #shortest_path
🟡1334.find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
🏷️ Tags
#graph #dynamic_programming #shortest_path
Telegraph
find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
有 n 个城市,按从 0 到 n-1 编号。给你一个边数组 edges,其中 edges[i] = [fromi, toi, weighti] 代表 fromi 和 toi 两个城市之间的双向加权边,距离阈值是一个整数 distanceThreshold。 返回能通过某些路径到达其他城市数目最少、且路径距离 最大 为 distanceThreshold 的城市。如果有多个这样的城市,则返回编号最大的城市。 注意,连接城市 i 和 j 的路径的距离等于沿该路径的所有边的权重之和。 示例 1: 输入:n…
👍1
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 秒……如此 往复 。
leetcode.com 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
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…