def ints() gets.not_nil!.split.map(&.to_i) end n, m = ints inf = 10**9 g = [-inf]*(n**2) m.times do a, b, c = ints a -= 1 b -= 1 g[a*n+b] = [g[a*n+b], c].max g[b*n+a] = [g[b*n+a], c].max end dp = [-inf] * ((1<<16) * 16) def index(i, j) i * 16 + j end n.times do |i| dp[index(1 << i, i)] = 0 end ans = -inf (1<> k & 1) == 0 t = index(i | 1 << k, k) dp[t] = [dp[t], dp[index(i, j)] + g[j*n+k]].max end end end end puts ans