#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long i64; typedef pair P; template const T INF = numeric_limits::max(); template const T SINF = numeric_limits::max() / 10; static const i64 MOD = 1000000007; //int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0}; //int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0}; //int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0}; //int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0}; struct edge { i64 from, to, cost; edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {} edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {} }; template vector make_v(size_t a){return vector(a);} template auto make_v(size_t a,Ts... ts){ return vector(ts...))>(a,make_v(ts...)); } template typename enable_if::value==0>::type fill_v(T &t,const V &v){t=v;} template typename enable_if::value!=0>::type fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); } //-----end of template-----// int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector item1(m), item2(m), score(m); for(int i = 0; i < m; ++i) cin >> item1[i] >> item2[i] >> score[i]; vector dp(1 << n, 0); for(int i = 0; i < (1 << n) - 1; ++i){ for(int j = 0; j < n; ++j){ if(i & (1 << j)) continue; int sum = 0; for(int k = 0; k < m; ++k){ if((i & (1 << item1[k])) && item2[k] == j){ sum += score[k]; } } dp[i | (1 << j)] = max(dp[i | (1 << j)], dp[i] + sum); } } cout << dp[(1 << n) - 1] << endl; }