Graph problem

Revision en3, by astral_projected, 2021-06-14 07:08:32

Number of ways to choose 3 nodes in a graph such that all are equidistant from each other.

Note: Number of edges = Number of nodes -1

Example:

Input: [1,2] [1,3] [1,4] [1,5]

Constraints 2 < N <= 10^4

Output: 4

My approach:

1.Bfs from all nodes

2.ans += NC3 : N = number of nodes on same level.

Problem: Unable to handle case of repetition, Pls look into it and provide me a solution for the same. Ps: ive been stuck on this for a long time :(

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English astral_projected 2021-06-14 07:08:32 84
en2 English astral_projected 2021-06-13 17:17:25 4
en1 English astral_projected 2021-06-13 17:16:16 415 Initial revision (published)