Pairing problem graph

sir my code giving correct output
but test case not pass

@YASHMATHURIA123
There are few mistakes in your code. I am pointing them

  1. Final ans can be greater than integer range. Use long long int to store it.
  2. Line 22 should be z+=dfs1(c,m);
  3. In function dfs, why are you iterating over l. l contain edges, it might be possible and it doesn’t have edges for all nodes. In that case your ans would not include these node. So iterate from i=0 to i<n

@YASHMATHURIA123
I have modified your code as per above comments. Check modified code here

sir line 22 m mai z=dfs1(c,m) likhungaa toh tab bhi toh sahi hai kyu ki har recursion m z=0 le raha hoon .

left or right subtree dono side ka return value add krna hoga. isliye z+=dfs1(c,m) nhi to sirf right subtree hi store hoga

@YASHMATHURIA123
I think you got the logic, please mark this doubt as resolved.