Skip to content

Practice Count Pairs Of Nodes

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1782
LeetCode Problem

Count Pairs Of Nodes

Problem Statement

The graph has n nodes; each edges[i] = [u,v] is an undirected connection. For each threshold in queries, count unordered node pairs a < b for which the number of graph edges incident to at least one of a or b is strictly greater than the threshold. An edge joining a to b counts once, while parallel edges are separate edges. Return counts in query order.

Source: Count Pairs Of Nodes on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 4, edges = [[1,2],[2,4],[1,3],[2,3],[2,1]], queries = [2,3]
Output
[6,5]

# Example 2

Input
n = 5, edges = [[1,5],[1,5],[3,4],[2,5],[1,3],[5,1],[2,3],[2,5]], queries = [1,2,3,4,5]
Output
[10,10,9,8,6]

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

Related LeetCode Problems

Practice more problems similar to Count Pairs Of Nodes.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.