#include #include #include #include #include #include #include using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 1'000'000'007; struct fast_io { fast_io(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; class union_find { int _setnum; vector par, nume; public: union_find(){ } union_find(int x){ par.resize(x); nume.resize(x); init(); } ~union_find(){ // } void clear(){ _setnum = 0; par.clear(); nume.clear(); } void init(){ _setnum = par.size(); for(int i = 0; i < par.size(); i++){ par[i] = i; nume[i] = 1; } } void resize(int x){ par.resize(x); nume.resize(x); init(); } int find(int x){ return par[x] == x ? x : par[x] = find(par[x]); } void unite(int x, int y){ x = find(x); y = find(y); if(x == y)return; _setnum--; if(nume[x] > nume[y]) std::swap(x,y); par[x] = y; nume[y] += nume[x]; } bool same(int x, int y){ return find(x) == find(y); } int numel(int x){ return nume[find(x)]; } int size(){ return par.size(); } int setnum(){ return _setnum; } }; vector>> kruskal(vector>>& edge, int V){ union_find uf(V); int res = 0, count = 0; vector>> tree(V); sort(edge.begin(), edge.end()); for(int i = 0; i < edge.size(); i++){ if(!uf.same(edge[i].second.first, edge[i].second.second)){ uf.unite(edge[i].second.first, edge[i].second.second); res += edge[i].first; tree[edge[i].second.first].push_back({edge[i].second.second, edge[i].first}); tree[edge[i].second.second].push_back({edge[i].second.first, edge[i].first}); count++; } } return tree; // if(count == V-1) return res; // return -1; } long long power(long long x, long long n){ long long ans = 1; for(;n;n >>= 1, x *= x, ans %= MOD, x %= MOD) if(n&1)ans*=x; return ans % MOD; } int ans = 0; int X; int solve(vector>> &tree, int cur, int per){ int sum = 1; for(pair nex : tree[cur]){ if(nex.first == per) continue; int temp = solve(tree, nex.first, cur); sum += temp; // cout<<"cur = "<>> edge; vector>> tree; cin>>N>>M>>X; for(int i = 0; i < M; i++){ int x, y, z; cin>>x>>y>>z; x--, y--; edge.push_back({z, {x, y}}); } tree = kruskal(edge, N); solve(tree, 0, -1); cout<