Mahmoud and Ehab and the bipartiteness
MediumRating 1300CodeforcesGraphs: BFS & DFS
Approach hintTry it first, then revealHide
Two-colour the tree with a DFS. Any added edge must join vertices of opposite colours, so count all cross-colour pairs and subtract the edges that already exist; the result needs 64-bit arithmetic.