← All problemsSign in

Connect The Chains

CodeChefRating 2964Open on judge ↗

A *chain* of length $M$ is a graph on $M$ vertices, such that its only edges are of the form $(i, i+1)$ for each $1 \leq i \lt M$. You are given $N$ chain graphs, each of length $M$. Vertex $j$ of the $i$-th chain graph has the integer $A_{i, j}$ written on it. You would like to merge all these chains into a single tree of $N\cdot M$ vertices, by adding $N-1$ extra edges. What is the **minim

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