Language: C++

#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }

#define ll long long int 
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

// #define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (2006)

ll n, m, x, p[MAXN];
vector<pi> v[MAXN];
vector<spi> e;
void myassert(bool b) {
	if(!b) {
		cout<<945693<<'\n';
		exit(0);
	}
}
struct _ufds {
	int p[MAXN];
	_ufds () { FOR(i,0,MAXN-1) p[i] = i; }
	void merge(ll x,ll y) {
		x=find(x), y=find(y);
		myassert(x>=0&&x<MAXN), myassert(y>=0&&y<MAXN);
		p[x]=y;
	}
	ll find(ll x) { return 0; return (p[x]==x)?x:p[x]=find(p[x]); }
	bool same(ll a,ll b) { return find(a) == find(b); }
} ufds;
int depth[MAXN], up[MAXN];
void dfs(ll x,ll par) {
	p[x]=par;
	for(auto i:v[x]) if(i.f^par) {
		depth[i.f]=depth[x]+1, up[i.f]=i.s, dfs(i.f, x);
	} 
}
ll mod = 1e9+7;
ll qexp(ll x,ll e) {
	if(e==0) return 1;
	ll half=qexp(x,e/2);
	half *= half, half %= mod;
	if(e&1) half*=x, half%=mod;
	return half;
}
int main()
{
	FAST
	cin>>n>>m>>x;
	FOR(i,0,m-1) {
		ll a, b, c; cin>>a>>b>>c;
		e.eb(c, pi(a, b));
	}
	sort(all(e));
	vector<bool> in(5000, 0);
	vector<ll> diff(5000, 0);
	ll mst = 0;
	for(int i=0;i<(int)e.size();++i) {
		ll a=e[i].s.f, b=e[i].s.s;
		if(ufds.same(a,b)) continue;
		ufds.merge(a, b);
		in[i]=1;
		v[a].eb(b, e[i].f);
		v[b].eb(a, e[i].f);
		mst += e[i].f;
	}
	dfs(1, 1);
	function<ll(ll, ll)> go_up=[&](ll x,ll y){
		ll ans = 0;
		while(x^y) {
			if(depth[x]<depth[y]) {
				swap(x,y);
			}
			ans = max(ans, up[x]);
			x=p[x];
		}
		return ans;
	};
	ll D = x-mst, equal=0, upper=0;
	FOR(i,0,siz(e)-1) if(!in[i]) {
		diff[i] = e[i].f-go_up(e[i].s.f, e[i].s.s), assert(diff[i] >= 0);
		if(D == diff[i]) {
			++ equal;
		} else if(D < diff[i]) {
			++ upper;
		}
	}
	if(D < 0) {
		cout<<0<<'\n'; return 0;
	} else if(D == 0) {
		cout << (qexp(2, n-1 + equal) - 2 + mod) % mod * qexp(2, upper) % mod<< '\n';
	} else {
		cout << (qexp(2, equal) - 1 + mod) % mod * qexp(2, upper) % mod * 2 % mod<< '\n';
	}
}
/*
lower, equal, upper
D = X - S
if(D < 0) cout<<0;
else if(D==0) {
	(qexp(2, n-1 + equal) - 1) * qexp(2, upper)  
} else  if(D > 0) {
	(qexp(2, equal) - 1) * qexp(2, upper) * 2
}
*/


Compiler output:
a.cc: In lambda function:
a.cc:96:34: error: no matching function for call to 'max(long long int&, int&)'
   96 |                         ans = max(ans, up[x]);
      |                               ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:96:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   96 |                         ans = max(ans, up[x]);
      |                               ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:96:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   96 |                         ans = max(ans, up[x]);
      |                               ~~~^~~~~~~~~~~~