inlineintdp(int s, int u, int d){ if (f[s][u][d] != -1) return f[s][u][d]; if (s == (1 << (u - 1))) return f[s][u][d] = 0; int& ans = f[s][u][d] = INF; for (registerint s1 = s; s1; s1 = (s1 - 1) & s) { if (!(s1 & (1 << (u - 1)))) continue; for (registerint v = 1; v <= N; ++v) { if (!(s & (1 << (v - 1)))) continue; if (w[u][v] == INF) continue; int s2 = s ^ s1; ans = min(ans, dp(s1, u, d) + dp(s2, v, d + 1) + w[u][v] * d); } } return ans; }
intmain(){ memset(w, 0x3f, sizeof(w)); memset(f, -1, sizeof(f)); scanf("%d%d", &N, &M); for (registerint i = 1; i <= M; ++i) { int u, v, t; scanf("%d%d%d", &u, &v, &t); w[u][v] = w[v][u] = min(w[u][v], t); } int ans = INF; for (registerint u = 1; u <= N; ++u) { ans = min(ans, dp((1 << N) - 1, u, 1)); } printf("%d", ans); return0; }