← All problemsSign in

Edges in Spanning Trees

CodeChefRating 2567Open on judge ↗

You are given two spanning trees $T_1$ and $T_2$ on the same set of $N$ vertices (numbered $1$ through $N$). For each edge $e_1$ in $T_1$, you have to calculate the number of edges $e_2 \in T_2$ which satisfy the following conditions: - $T_1 - e_1 + e_2$ (the graph formed by removing the edge $e_1$ from $T_1$ and adding the edge $e_2$) is a spanning tree - $T_2 - e_2 + e_1$ is also a spanning tree

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start