Pairing//////////////////////


getting tle for one test case

There are several things wrong with your code.
First of all you need to use adjacency list when n is of the order of 10^5 because first you aren’t allowed a 2-d array of size a[10^5][10^5] and even if you were allowed that much size it would make your bfs O(n^2) because you are checking each of the n-1 nodes for every node thus resulting in TLE.

Second once you take an adjacency list ,your loop to count answers is also inefficient,which in itself is O(n^2). If you want I can share the code