Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-087

Wedge Count

Problem

Count the wedges of an undirected graph: unordered pairs of edges that share a center, including wedges whose endpoints are also connected.

A node of degree d contributes d * (d - 1) / 2 wedges, so sum that over all nodes. edges is a list of [u, v] pairs.

Hint

Wedge count relates to degrees by the handshake-style identity sum of d choose 2.

Test cases

case 1
in: [4,[[0,1],[0,2],[0,3]]]
expected: 3
case 2
in: [4,[[0,1],[1,2],[2,3]]]
expected: 2
case 3
in: [3,[[0,1],[1,2],[2,0]]]
expected: 3
case 4
in: [4,[[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]]]
expected: 12
Starter codePython
def wedge_count(n, edges):
    # Your code here
    pass

4 test cases · run your code against them in the editor