#include int score[14][14], dp[1 << 14], queue[1 << 14], get = 0, set = 0; int main() { int n, m, i, j; scanf("%d%d", &n, &m); for(i = 0; i < m; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); score[a][b] = c; } dp[0] = 1; //queue[0] = 0; set++; while(get != set) { for(i = 0; i < n; i++) { if( ( queue[get] & (1 << i) ) == 0 ) { int next = queue[get] + (1 << i); int s = dp[ queue[get] ]; for(j = 0; j < n; j++) { if( queue[get] & (1 << j) ) { s += score[j][i]; } } if(dp[next] == 0) { queue[set] = next; set++; } dp[next] = dp[next] < s ? s : dp[next]; } } get++; } printf("%d\n", dp[(1 << n) - 1] - 1); return 0; }