1724. Checking Existence of Edge Length Limited Paths II
https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths-ii
Description
An undirected graph of n
nodes is defined by edgeList
, where edgeList[i] = [ui, vi, disi]
denotes an edge between nodes ui
and vi
with distance disi
. Note that there may be multiple edges between two nodes, and the graph may not be connected.
Implement the DistanceLimitedPathsExist
class:
DistanceLimitedPathsExist(int n, int[][] edgeList)
Initializes the class with an undirected graph.boolean query(int p, int q, int limit)
Returnstrue
if there exists a path fromp
toq
such that each edge on the path has a distance strictly less thanlimit
, and otherwisefalse
.
Example 1:
**Constraints:**
2 <= n <= 104
0 <= edgeList.length <= 104
edgeList[i].length == 3
0 <= ui, vi, p, q <= n-1
ui != vi
p != q
1 <= disi, limit <= 109
At most
104
calls will be made toquery
.
ac
Last updated