In the easy version, \(m = n-1\) and there exists a path between \(u\) and \(v\) for all \(u, v\) (\(1 \leq u, v \leq n\)).
After a worker's strike organized by the Dementors asking for equal rights, the prison of Azkaban has suffered some damage. After settling the spirits, the Ministry of Magic is looking to renovate the prison to ensure that the Dementors are kept in check. The prison consists of \(n\) prison cells and \(m\) bi-directional corridors. The \(i^{th}\) corridor is from cells \(u_i\) to \(v_i\). A subset of these cells \(S\) is called a complex if any cell in \(S\) is reachable from any other cell in \(S\). Formally, a subset of cells \(S\) is a complex if \(x\) and \(y\) are reachable from each other for all \(x, y \in S\), using only cells from \(S\) on the way. The funding required for a complex \(S\) consisting of \(k\) cells is defined as \(k^2\).
As part of your Intro to Magical Interior Design course at Hogwarts, you have been tasked with designing the prison. The Ministry of Magic has asked that you divide the prison into \(2\) complexes with \(\textbf{exactly one corridor}\) connecting them, so that the Dementors can't organize union meetings. For this purpose, you are allowed to build bi-directional corridors. The funding required to build a corridor between any \(2\) cells is \(c\).
Due to budget cuts and the ongoing fight against the Death Eaters, you must find the \(\textbf{minimum total funding}\) required to divide the prison as per the Ministry's requirements or \(-1\) if no division is possible.
Note: The total funding is the sum of the funding required for the \(2\) complexes and the corridors built. If after the division, the two complexes have \(x\) and \(y\) cells respectively and you have built a total of \(a\) corridors, the total funding will be \(x^2 + y^2 + c \times a\). Note that \(x+y=n\).