#include using namespace std; vector> adj[100]; int vis[100]; int Prims(int src, int val) { int cost=0; priority_queue,vector>,greater>>pq; pq.push({0,src}); while(!pq.empty()) { pair p=pq.top(); pq.pop(); int u=p.second; int ct=p.first; if(vis[u]) continue; cost += ct; vis[u] = 1; for(auto it : adj[u]){ int adjNode = it[0]; int wt = it[1]; if(wt<=val){ pq.push({wt, adjNode}); } } } return cost; } int main(){ int n, m; cin >> n >> m; while(m--){ int p, q, w; cin >> p >> q >> w; adj[p].push_back({q, w}); adj[q].push_back({p, w}); } vector ans; for(int i = 1; i <= n; i++){ if(!vis[i]){ ans.push_back(Prims(i, 6)); } } cout << ans.size() << endl; for(auto x : ans) cout << x << endl; }