import java.util.Random; import java.util.Scanner; public class Main { private static double sigmoid(double x) { return 1 / (1 + Math.exp(-x)); } public static void main(String[] argv) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int m = scanner.nextInt(); int[][] p = new int[n][n]; for (int i = 0; i < m; i++) { int mae = scanner.nextInt(); int ato = scanner.nextInt(); p[ato][mae] = scanner.nextInt(); } int[] ans = new int[n]; for (int i = 0; i < n; i++) ans[i] = i; Random r = new Random(); int count = 0; double T = 10000; while (T > 0.0001 && (count++) < 100000) { int a = r.nextInt(n); int b = r.nextInt(n); if (a == b) continue; if (a > b) { int t = b; b = a; a = t; } int diff = p[ans[a]][ans[b]] - p[ans[b]][ans[a]]; for (int i = a + 1; i <= b - 1; i++) { diff -= p[ans[b]][ans[i]]; diff += p[ans[a]][ans[i]]; } double prob = 0.9; if (diff <= 0.0) { prob = 0.5 * Math.exp(diff / T); } // System.out.println("diff=" + diff + ", prob=" + prob); if (r.nextDouble() < prob) { // System.out.println("change " + a + ", " + b); int tt = ans[b]; ans[b] = ans[a]; ans[a] = tt; } T *= 0.99; } int score = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { score += p[ans[j]][ans[i]]; } } System.out.println(score); for (int i = 0; i < n; i++) { System.out.print(ans[i] + " "); } } }