Language: C++

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}


const ll MOD = 1e9 + 7;


struct UnionFind {
  vector<int> data; // 根の場合は集合の大きさ*-1、子の場合は親の番号が入る
  UnionFind(int size) : data(size, -1) { }
  bool link(int x, int y) { //新たな併合を行うとtrue
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  int root(int x) { // 代表元を返す
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) { // 要素xが含まれる集合の大きさ
    return -data[root(x)];
  }
  bool same(int x, int y) { // 同じ集合ならtrue
    return root(x) == root(y);
  }
};


ll mod_pow(ll a, ll b, ll p) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return res;
}

struct Edge {
  int a, b;
  ll w;
};

vector<vector<int>> g;
vector<Edge> es;
int N, M;

vector<ll> hist;
void dfs(int from, int to, int prev) {
  if (from == to) {
    throw 42;
  }
  for (int i : g[from]) {
    int nxt = from ^ es[i].a ^ es[i].b;
    if (nxt == prev) continue;
    hist.push_back(es[i].w);
    dfs(nxt, to, from);
    hist.pop_back();
  }
}

// コストx以下の全域木はすべて単色であるような、辺の塗り方の場合の数
ll f(const ll x) {

  vector<int> use(M);
  UnionFind uf(N);

  ll mst_size = 0;
  for (int i = 0; i < (int)es.size(); i++) {
    const Edge& e = es[i];
    if (uf.link(e.a, e.b)) {
      mst_size += e.w;
      use[i] = 1;
    }
  }

  if (mst_size > x) return mod_pow(2, M, MOD);
  ll res = 2;

  for (int i = 0; i < (int)es.size(); i++) if (!use[i]) {
    const Edge& e = es[i];

    hist.clear();
    try {
      dfs(e.a, e.b, -1);
    } catch (int e) {
    }
    ll ma = *max_element(ALL(hist));
    ll diff = e.w - ma;

    if (mst_size + diff > x) res = (res * 2) % MOD;
  }
  return res;
}

int main2() {
  N = nextLong();
  M = nextLong();
  ll X = nextLong();

  es.clear();
  g.clear();
  g.assign(N);

  REP(i, M) {
    int a = nextLong() - 1;
    int b = nextLong() - 1;
    ll w = nextLong();
    es.push_back((Edge){a, b, w});
  }

  sort(ALL(es), [](const Edge&a, const Edge&b) {
    return a.w < b.w;
  });

  REP(i, M) {
    g[es[i].a].push_back(i);
    g[es[i].b].push_back(i);
  }

  ll ans = f(X-1) - f(X);
  ans = (ans % MOD + MOD) % MOD;
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Compiler output:
a.cc: In function 'int main2()':
a.cc:116:11: error: no matching function for call to 'std::vector<std::vector<int> >::assign(int&)'
  116 |   g.assign(N);
      |   ~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:828:9: note: candidate: 'template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]'
  828 |         assign(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:828:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_vector.h:808:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; size_type = long unsigned int; value_type = std::vector<int>]'
  808 |       assign(size_type __n, const value_type& __val)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:808:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_vector.h:855:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]'
  855 |       assign(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:855:43: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<std::vector<int> >'
  855 |       assign(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~