Leetcode-cn.com 2021-08-02
🟡 743.network-delay-time
🏷️ Tags
#depth_first_search #breadth_first_search #graph #shortest_path #heap_priority_queue
Description
有
给你一个列表
现在,从某个节点
Example
🟡 743.network-delay-time
🏷️ Tags
#depth_first_search #breadth_first_search #graph #shortest_path #heap_priority_queue
Description
有
n 个网络节点,标记为 1 到 n。给你一个列表
times,表示信号经过 有向 边的传递时间。 times[i] = (ui, vi, wi),其中 ui 是源节点,vi 是目标节点, wi 是一个信号从源节点传递到目标节点的时间。现在,从某个节点
K 发出一个信号。需要多久才能使所有节点都收到信号?如果不能使所有节点收到信号,返回 -1 。Example
输入:times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2
输出:2
Leetcode-cn.com 2021-08-24
🟡 787.cheapest-flights-within-k-stops
🏷️ Tags
#depth_first_search #breadth_first_search #graph #dynamic_programming #shortest_path #heap_priority_queue
Description
有
现在给定所有的城市和航班,以及出发城市
Example
🟡 787.cheapest-flights-within-k-stops
🏷️ Tags
#depth_first_search #breadth_first_search #graph #dynamic_programming #shortest_path #heap_priority_queue
Description
有
n 个城市通过一些航班连接。给你一个数组 flights ,其中 flights[i] = [fromi, toi, pricei] ,表示该航班都从城市 fromi 开始,以价格 toi 抵达 pricei。现在给定所有的城市和航班,以及出发城市
src 和目的地 dst,你的任务是找到出一条最多经过 k 站中转的路线,使得从 src 到 dst 的 价格最便宜 ,并返回该价格。 如果不存在这样的路线,则输出 -1。Example
输入:
n = 3, edges = [[0,1,100],[1,2,100],[0,2,500]]
src = 0, dst = 2, k = 1
输出: 200
解释:
城市航班图如下
从城市 0 到城市 2 在 1 站中转以内的最便宜价格是 200,如图中红色所示。
Leetcode.com 2021-09-12
🔴 882.reachable-nodes-in-subdivided-graph
🏷️ Tags
#graph #shortest_path #heap_priority_queue
Description
You are given an undirected graph (the "original graph") with
The graph is given as a 2D array of
To subdivide the edge
In this new graph, you want to know how many nodes are reachable from the node
Given the original graph and
Example
🔴 882.reachable-nodes-in-subdivided-graph
🏷️ Tags
#graph #shortest_path #heap_priority_queue
Description
You are given an undirected graph (the "original graph") with
n nodes labeled from 0 to n - 1. You decide to subdivide each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.The graph is given as a 2D array of
edges where edges[i] = [ui, vi, cnti] indicates that there is an edge between nodes ui and vi in the original graph, and cnti is the total number of new nodes that you will subdivide the edge into. Note that cnti == 0 means you will not subdivide the edge.To subdivide the edge
[ui, vi], replace it with (cnti + 1) new edges and cnti new nodes. The new nodes are x1, x2, ..., xcnti, and the new edges are [ui, x1], [x1, x2], [x2, x3], ..., [xcnti+1, xcnti], [xcnti, vi].In this new graph, you want to know how many nodes are reachable from the node
0, where a node is reachable if the distance is maxMoves or less.Given the original graph and
maxMoves, return the number of nodes that are reachable from node 0 in the new graph.Example
Input: edges = [[0,1,10],[0,2,1],[1,2,2]], maxMoves = 6, n = 3
Output: 13
Explanation: The edge subdivisions are shown in the image above.
The nodes that are reachable are highlighted in yellow.
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…