#include #define INF 2147483647 #define INF_LL 9223372036854775807 #define MOD 1000000007 using namespace std; typedef long long int ll; typedef unsigned long long int ull; vector > mat; int N, M; int dfs(int pos, int dist, vector used) { int tmp = dist; for (int i = 0; i < N; i++) { if (mat[pos][i] != -1 && !used[i]) { used[i] = true; tmp = max(tmp, dfs(i, dist + mat[pos][i], used)); used[i] = false; } } return tmp; } int main() { cin >> N >> M; mat = vector >(N, vector(N, -1)); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; mat[a][b] = mat[b][a] = max(c,mat[a][b]); } int ans = -1; for (int i = 0; i < N; i++) { vector tmp(N, false); tmp[i] = true; ans = max(ans,dfs(i, 0, tmp)); } cout << ans << endl; }