公式

A - Four TSP 解説 by evima


Consider the two edges not included in the cycle among the six edges. There are the following three possible pairs of edges:

  • Edge \((1,2)\) and edge \((3,4)\)
  • Edge \((1,3)\) and edge \((2,4)\)
  • Edge \((1,4)\) and edge \((2,3)\)

Let \(A, B, C\) be the sum of weights of the edges in these three groups, respectively. The number of such graphs is \((A-1)(B-1)(C-1)\), and \(f(G) = K - \max(A,B,C)\) for each graph \(G\), so the sum of \(f(G)\) when \(A,B,C\) are fixed can be found in \(O(1)\).

Since \(A+B+C=K\), we can enumerate all \(A,B,C\) in \(O(K^2)\), so this problem can be solved in \(O(K^2)\).

投稿日時:
最終更新: