Language: C++

#include <bits/stdc++.h>

typedef long long ll;
const int N = 100054, M = N * 2, mod = 1000000007;

struct edge {
	int u, v, w;
	edge (int u0 = 0, int v0 = 0, int w0 = 0) : u(u0), v(v0), w(w0) {}
	edge * read() {return scanf("%d%d%d", &u, &v, &w), this;}
	bool operator < (const edge &B) const {return w < B.w;}
} e[M];

int V, E;
bool mst[M], mist[M];
int p[N];

inline void up(int &x, const int y) {x < y ? x = y : 0;}
inline int max(const int x, const int y) {return x < y ? y : x;}

ll PowerMod(ll a, int n, ll c = 1) {for (; n; n >>= 1, a = a * a % mod) if (n & 1) c = c * a % mod; return c;}

int ancestor(int x) {return p[x] == x ? x : (p[x] = ancestor(p[x]));}

inline bool test(int x, int y, bool un = false) {
	if ((x = ancestor(x)) == (y = ancestor(y))) return true;
	return un && (p[x] = y), false;
}

namespace Tree {
	const int N = ::N, M = ::M, LN = 18;

	int E;
	edge e[M];
	int first[N], next[M];
	int P[LN][N], *p = *P, m[LN][N], dep[N];

	inline void init() {E = 0, memset(first, 0, sizeof first);}

	inline void addedge(int u, int v, int w) {
		e[++E] = edge(u, v, w), next[E] = first[u], first[u] = E;
		e[++E] = edge(v, u, w), next[E] = first[v], first[v] = E;
	}

	void dfs(int x) {
		int i, y;
		for (i = 0; i < LN - 1 && P[i][x]; ++i)
			P[i + 1][x] = P[i][P[i][x]],
			m[i + 1][x] = max(m[i][P[i][x]], m[i][x]);
		for (i = first[x]; i; i = next[i])
			if ((y = e[i].v) != p[x])
				p[y] = x, dep[y] = dep[x] + 1,
				m[0][y] = e[i].w, dfs(y);
	}

	int query(int x, int y) {
		int i, ret = 0;
		if (dep[x] < dep[y]) std::swap(x, y);
		for (i = LN - 1; i >= 0; --i)
			if (dep[x] - (1 << i) >= dep[y]) up(ret, m[i][x]), x = P[i][x];
		if (x == y) return ret;
		for (i = LN - 1; i >= 0; --i)
			if (P[i][x] != P[i][y])
				up(ret, m[i][x]), x = P[i][x],
				up(ret, m[i][y]), y = P[i][y];
		return max(ret, max(m[0][x], m[0][y]));
	}
}

int main() {
	int i, j, k, u, v, w, w0, z0, lt = 0, eq = 0, gt = 0;
	ll X, MST = 0, ans;
	scanf("%d%d%lld", &V, &E, &X);
	assert(E >= V - 1);
	for (i = 0; i < E; ++i) e[i].read();
	if (V <= 2) {puts("0"); return;}
	std::sort(e, e + E);
	for (i = 1; i <= V; ++i) p[i] = i;
	for (j = i = 0; i < E; i = j) {
		for (; e[i].w == e[j].w; ++j);
		for (k = i; k < j; ++k) mst[k] = ancestor(e[k].u) != ancestor(e[k].v);
		for (k = i; k < j; ++k) if (mist[k] = !test(e[k].u, e[k].v, true)) MST += e[k].w;
	}
	if (X < MST) ans = 0;
	else if (X == MST)
//		fprintf(stderr, "MST = X = %lld\n", X),
		z0 = std::count(mst, mst + E, false),
		ans = PowerMod(2, E) - PowerMod(2, z0 + 1);
	else {
//		fprintf(stderr, "MST = %lld, X = %lld\n", MST, X);
		Tree::init();
		for (i = 0; i < E; ++i) if (mist[i]) Tree::addedge(e[i].u, e[i].v, e[i].w);
		Tree::dfs(1);
		for (i = 0; i < E; ++i) if (!mst[i]) {
			u = e[i].u, v = e[i].v, w = e[i].w, w0 = Tree::query(u, v);
//			fprintf(stderr, "(%d, %d, %d) not in MST, w0 = %d\n", u, v, w, w0);
			assert(w > w0);
			if (w - w0 < X - MST) ++lt;
			else if (w - w0 == X - MST) ++eq;
			else ++gt;
		}
		ans = 2 * (PowerMod(2, eq + gt) - PowerMod(2, gt)) % mod;
	}
	return printf("%lld\n", ans + (ans >> 63 & mod)), 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:75:33: error: return-statement with no value, in function returning 'int' [-fpermissive]
   75 |         if (V <= 2) {puts("0"); return;}
      |                                 ^~~~~~