#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long Int; typedef pair P; #define rep(i,x) for(Int i = 0; i < (Int)(x); i++) #define rrep(i,x) for(Int i = ((Int)(x) - 1); i >= 0; i--) #define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define all(x) (x).begin(), (x).end() #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); #define pb push_back #define MX 100010 template void chmin(T1 &a, T2 b){if(a>b)a=b;} template void chmax(T1 &a, T2 b){if(a par; UnionFind(int n) : par(n){ for(int i = 0; i < n; i++) par[i] = i; } int root(int x){ if(par[x] == x) return x; return par[x] = root(par[x]); } void Union(int x, int y){ int nx = root(x); int ny = root(y); if(nx == ny) return; par[nx] = ny; } bool same(int x, int y){ int nx = root(x); int ny = root(y); return nx == ny; } }; int n,m; int graph[1010][1010]; bool visited[1010]; int dfs(int x){ if(x == n) return 0; int ans = 0; for(int i = 0; i < n; i++){ int ret = 0; if(graph[x][i] == -1) continue; if(visited[i]) continue; ret += graph[x][i]; visited[i] = true; ret += dfs(i); ans = max(ret,ans); visited[i] = false; } return ans; } int main(){ cin >> n >> m; memset(graph,-1,sizeof(graph)); memset(visited,false,sizeof(visited)); UnionFind tree(n); rep(i,m){ int a,b,c; cin >> a >> b >> c; a--; b--; graph[a][b] = graph[b][a] = c; tree.Union(a,b); } visited[0] = true; int ans = dfs(0); vector check; check.push_back(0); for(int j = 0; j < n; j++){ bool ok = true; for(int i = 0; i < check.size(); i++){ if(i==j) ok = false; if(tree.same(j,check[i])) ok = false; } if(ok){ ans += dfs(j); check.push_back(j); } } cout << ans << endl; return 0; }