module main; // https://kmjp.hatenablog.jp/entry/2014/12/08/0900 より // 順列 全探索 bitDP import std; void main() { // 入力 int N, M; readln.chomp.formattedRead("%d %d", N, M); auto item1 = new int[](M), item2 = new int[](M), S = new int[](M); auto G = new int[][](N, N); foreach (i; 0 .. M) { readln.chomp.formattedRead("%d %d %d", item1[i], item2[i], S[i]); G[item1[i]][item2[i]] = S[i]; } // 答えの計算 int ans = 0; auto V = iota(0, N).array; do { int tmp = 0; foreach (x; 0 .. N) { foreach (y; 0 .. x) tmp += G[V[y]][V[x]]; } ans = max(ans, tmp); } while (V.nextPermutation); // 答えの出力 writeln(ans); }