Language: C++

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define fi first 
#define se second

const ll MOD = (ll)1e9 + 7;

//Class - Union Find Tree
template<class T> class Union_Find {
public:
	vector<int> prnt;
	vector<int> rank;
	vector<T> dist;

	Union_Find(int N = 1) :prnt(vector<int>(N)), rank(vector<int>(N, 0)), dist(vector<int>(N, 0)) {
		for (int i = 0; i < N; ++i) prnt[i] = i;
	}

	int root(int x) {
		if (prnt[x] == x) return x;
		else {
			int r = root(prnt[x]);
			dist[x] += dist[prnt[x]];
			return prnt[x] = r;
		}
	}

	T updated_dist(int x) {
		root(x);
		return dist[x];
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y, T d) {
		d += updated_dist(x);
		d -= updated_dist(y);
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) {
			swap(x, y);
			d = -d;
		}
		if (rank[x] == rank[y]) ++rank[x];
		prnt[y] = x;
		dist[y] = d;
		return true;
	}

	T diff(int x, int y) {
		return updated_dist(y) - updated_dist(x);
	}
};

int main() {
	ll N, M, X; cin >> N >> M >> X;
	vector<pair<ll, pair<int, int>>> edge(M);

	//入力
	REP(i, M) {
		int U, V;
		ll W;
		cin >> U >> V >> W;
		U--;
		V--;
		edge[i] = { W,{ U,V } };
	}

	//重みでソート
	sort(ALL(edge));

	//コーナーケース
	if (N <= 2 || M < 2) {
		cout << 0 << endl;
		return 0;
	}

	//2の累乗をメモ
	VL pow2(M + 1, 1);
	FOR(i, 1, M + 1) pow2[i] = (pow2[i - 1] * 2) % MOD;

	//M-1個の最小全域木の重み
	VL sum(M - 1, 0);
	FOR(B, 1, M) {

		//UnionFind木
		Union_Find<int> UF(N);

		//最小辺とBを用いた最小全域木
		sum[B - 1] += edge[0].fi + edge[B].fi;
		UF.merge(edge[0].se.fi, edge[0].se.se, 1);
		UF.merge(edge[B].se.fi, edge[B].se.se, 1);

		//クラスカル法による最小全域木の構築
		FOR(j, 1, M) {
			int U = edge[j].se.fi;
			int V = edge[j].se.se;
			ll W = edge[j].fi;

			//連結済ならcontinue
			if (UF.same(U, V)) continue;

			//辺をmergeし重みを加える
			UF.merge(U, V, 1);
			sum[B - 1] += W;
		}
	}

	//最小全域木の重みでソート
	sort(ALL(sum));

	//軽い方からsum[i] == Xとなるものを数え上げ
	REP(i, M - 1) if (sum[i] == X) (ans += ((2 * pow2[M - 2 - i]) % MOD)) %= MOD;

	cout << ans << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:79:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   79 |         sort(ALL(edge));
      |         ^~~~
      |         short
a.cc:88:9: error: 'VL' was not declared in this scope
   88 |         VL pow2(M + 1, 1);
      |         ^~
a.cc:89:26: error: 'pow2' was not declared in this scope
   89 |         FOR(i, 1, M + 1) pow2[i] = (pow2[i - 1] * 2) % MOD;
      |                          ^~~~
a.cc:92:11: error: expected ';' before 'sum'
   92 |         VL sum(M - 1, 0);
      |           ^~~~
      |           ;
a.cc:99:17: error: 'sum' was not declared in this scope
   99 |                 sum[B - 1] += edge[0].fi + edge[B].fi;
      |                 ^~~
a.cc:119:18: error: 'sum' was not declared in this scope
  119 |         sort(ALL(sum));
      |                  ^~~
a.cc:9:19: note: in definition of macro 'ALL'
    9 | #define ALL(obj) (obj).begin(),(obj).end()
      |                   ^~~
a.cc:122:41: error: 'ans' was not declared in this scope; did you mean 'abs'?
  122 |         REP(i, M - 1) if (sum[i] == X) (ans += ((2 * pow2[M - 2 - i]) % MOD)) %= MOD;
      |                                         ^~~
      |                                         abs
a.cc:122:54: error: 'pow2' was not declared in this scope
  122 |         REP(i, M - 1) if (sum[i] == X) (ans += ((2 * pow2[M - 2 - i]) % MOD)) %= MOD;
      |                                                      ^~~~
a.cc:124:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
  124 |         cout << ans << endl;
      |                 ^~~
      |                 abs