Travelling in the Graph
You are given a graph with $N$ vertices (numbered $1$ to $N$) and $M$ bidirectional edges, which doesn't contain multiple edges or self-loops — that is, the given graph is a simple undirected graph. For each pair of vertices $a, b$ such that $1 \leq a, b \leq N$, it is possible to add a new edge between vertices $a$ and $b$ to the graph, with a cost of $(a - b)^2$. Find the minimum cost of addin
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.
Sign in to chat with the tutor and save your progress.
Sign in to start