LeetCode 1782. Count Pairs Of Nodes
Last updated
Last updated
You are given an undirected graph represented by an integer n
, which is the number of nodes, and edges
, where edges[i] = [ui, vi]
which indicates that there is an undirected edge between ui
and vi
. You are also given an integer array queries
.
The answer to the jth
query is the number of pairs of nodes (a, b)
that satisfy the following conditions:
a < b
cnt
is strictly greater than queries[j]
, where cnt
is the number of edges incident to a
or b
.
Return an array answers
such that answers.length == queries.length
and answers[j]
is the answer of the jth
query.
Note that there can be repeated edges.
Example 1:
Example 2:
Constraints:
2 <= n <= 2 * 10^4
1 <= edges.length <= 10^5
1 <= ui, vi <= n
ui != vi
1 <= queries.length <= 20
0 <= queries[j] < edges.length