eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Simon the Spider

Simon the Spider

\includegraphics{https://static.e-olymp.com/content/3b/3b1078e8c850f75af976d5ab75cee089aec3f6fc.jpg} In the \textit{Mosquito} problem, you have seen that the potential reproductive capabilities of insects are very high. Fortunately for us humans, the insects also have natural enemies that help to reduce their population. Spiders belong among the best known insect predators, so there is no wonder we included them in this problem set. Simon the Spider ate many insects this summer and got fat. The threads of his web will soon be too thin to carry him and so he needs to reinforce them. Since fat spiders are also lazy, Simon wants to use as little material as possible --- well, you know that spiders have to produce the material for building webs by themselves. Finally, he decided to reinforce only some of the threads, but it is important that every node of his web must be reachable over the reinforced links. Additionally, Simon plans to spend his free time on one of the reinforced links and he wants this one link to be long. Therefore, when calculating the total length of all reinforced links, the length of the longest reinforced link will be\textit{subtracted} instead of added. Help Simon to decide which links should be reinforced to have the lowest possible total length under these circumstances. \InputFile The input consists of descriptions of several webs. The first line of each description contains two numbers: the number \textbf{N} (\textbf{2} ≤ \textbf{N} ≤ \textbf{2000}) of nodes in the web and the number \textbf{M} (\textbf{0} ≤ \textbf{M} ≤ \textbf{1000000}) of the links between pairs of nodes. Each of the following \textbf{M} lines describes one link. The description of each link contains three positive integers \textbf{u_i}, \textbf{v_i}, \textbf{i}, where \textbf{u_i}and \textbf{v_i} (\textbf{1} ≤ \textbf{u_i}, \textbf{v_\{i \}}≤ \textbf{N} and \textbf{u_i} ≠ \textbf{v_i}) are the two nodes connected by the link and \textbf{i} is its length (\textbf{1} ≤ \textbf{i} ≤ \textbf{100000}). \OutputFile For each web, print a single line with the minimum possible total length of reinforced links under all given conditions. Remember that the total length is the sum of the lengths of all reinforced links minus twice the length of the longest reinforced link. If it is not possible to reach every node from every other node through a sequence of links, then print "\textbf{disconnected}" instead of the cost.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
3 1
1 2 5
4 5
1 2 5
2 3 6
3 4 8
3 4 4
1 4 2
Выходные данные #1
disconnected
-1