using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; class Magatro { static int[,] AA; static int M,N; static int max = 0; static void Main() { string[] s = Console.ReadLine().Split(' '); N = int.Parse(s[0]); M = int.Parse(s[1]); AA = new int[N, N]; for(int i = 0; i < M; i++) { s = Console.ReadLine().Split(' '); AA[int.Parse(s[0]), int.Parse(s[1])] = int.Parse(s[2]); } int[] S = new int[N]; for(int i = 0; i < N; i++) { S[i] = i; } while (next_permutation(S)) { // Console.WriteLine(string.Join(" ",S.Select(i=>i.ToString()))); max = Math.Max(max, Score(S)); } Console.WriteLine(max); } static public bool next_permutation(int[] perm) { int n = perm.Length; int k = -1; for (int i = 1; i < n; i++) if (perm[i - 1] < perm[i]) k = i - 1; if (k == -1) { for (int i = 0; i < n; i++) perm[i] = i; return false; } int l = k + 1; for (int i = l; i < n; i++) if (perm[k] < perm[i]) l = i; int t = perm[k]; perm[k] = perm[l]; perm[l] = t; Array.Reverse(perm, k + 1, perm.Length - (k + 1)); return true; } static int Score(int[] items) { int res = 0; for(int i = 0; i < N-1; i++) { for(int j = i + 1; j < N; j++) { res += AA[items[i], items[j]]; } } return res; } }