Technically this is not an answer to your basic question. This is an answer to your actual question which is: How do I think about this problem, surely there is a better way than brute force?
As with any problem think how you would do this yourself.
You've been given a list of connections and distances that would be traveled on them. Which connection would give you the greatest chance of being apart of the longest two connection route?
You could pick the smallest, but that would only contribute a little distance to the total traveled. How about picking the biggest? Would that be more effective?
Okay so now is the job done? No. You need another connection - but how to pick it? should you pick the next smallest, or the next largest? Is there some other property that needs to hold, oh look one city must be shared between the two edges. So can you pick the same edge? No.
Hmm, so grab all the edges that connect to the first or last city. Wait that includes the first edge, okay get rid of that edge. Now which edge should be picked? The smallest, or the biggest?
Are you done now? You've got two edges, they connect to each other. Are they the longest? How are you certain?
How can you possibly work out that you are certain? Hmm, the longest possible connection would be along the two longest edges (lets just imagine they are connected). Every other connection must be shorter than this. Is this useful? well if they are the two edges just picked great, they are the longest, nothing left to do. But. What if they are not? Hmm, not very helpful.
Okay, back to the drawing board. How do you know that you've got the longest route, given you somehow picked the correct first edge. Is it the shortest or longest edge that's connected. Can you ensure the route in that pair is the biggest possible? How?
Now how do you pick the correct first edge? So that the route is the longest possible? Nothing coming to mind. Okay, what does that second edge tell you? Well it must be shorter than the first edge, otherwise you would have picked it first. Which means the second edge must be smaller, if you picked an even smaller edge will that make the route bigger, or smaller? Maybe you can exclude those edges that can only make a shorter overall route. You can exclude that second edge too, So you only need to look at those edges that could make a longer route than this one. (otherwise you already have the longest).
hmm, so if you pick the biggest edge first, and then pair it. In that pair swapping either edge with any other edge must make a shorter route. cool. But is there another pair of edges made of edges that can be longer? Maybe 7+3 > 8+1. One edge has to get bigger, and the other slightly smaller.
So maybe you can refine the possible solutions down till there is one clear winner. Do you need to look at every row between the pair of rows? probably not 8+1 > 4+3.
The above is a series of rough questions I asked myself till I became confident I could actually write code to solve it. I'll leave understanding those questions and turning that into code as an exercise for you. To be clear the algorithm is roughly O(log(N)K), way better than brute force O(N^2).