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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline void chmin(T &l,T r){l=min(l,r);}
template <typename T>inline void chmax(T &l,T r){l=max(l,r);}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
LL N,M,T;
int a[212345];
int b[212345];
int c[212345];
int d[212345];
int exist[212345];
typedef vector<int> V;
typedef vector<V> VV;
VV g;
typedef pair<int,int> P;
void dijkstra(){
    priority_queue<P> que;
    que.push(P(0,1));
    d[1]=0;
    while(que.size()){
        int t,v;
        tie(t,v)=que.top();t*=-1;que.pop();
        if(t<=T)exist[v]=1;
        if(d[v]<t)continue;
        for(auto &e:g[v]){
            int u=v^a[e]^b[e];
            int cost=d[v]+1;
            if(cost<=c[e]&&d[u]>cost){
                d[u]=cost;
                que.push(P(-cost,u));
            }
        }
    }
}

namespace _DSU{
    int cnt=0;
    LL mem[5][212345];
    LL *get(){
        return mem[cnt++];
    }
}
int now;
const LL INF=1e12;
struct UnionFind{
    LL *par,*rank,*res,*t,*sz;
    LL find(LL x){
        res[x]+=sz[x]*(t[x]-now);
        t[x]=now;
        if(par[x]==x){
            return x;
        }
        else {
            LL p=find(par[x]);
            sz[p]+=sz[x];sz[x]=0;
            chmax(res[p],res[x]);
            res[x]=-INF;
            return p;
        }
    }
    UnionFind(int n,LL *par,LL *rank,LL* res,LL *t,LL *sz)
        :par(par),rank(rank),res(res),t(t),sz(sz){
        FOR(i,1,n+1){
            par[i]=i,rank[i]=0,sz[i]=1;
            if(exist[i]){
                res[i]=0;
                t[i]=T;
            }
            else{
                t[i]=T;
                res[i]=-INF;
            }
        }
    }
    UnionFind(int n):UnionFind(n,_DSU::get(),_DSU::get(),_DSU::get(),_DSU::get(),_DSU::get()){}
    bool unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y)return false;
        if(rank[x]>rank[y])swap(x,y);
        //cout<<res[x]<<" "<<res[y]<<endl;
        sz[y]+=sz[x];sz[x]=0;
        chmax(res[y],res[x]);
        res[x]=-INF;
        par[x]=y;
        if(rank[x]==rank[y])rank[y]++;
        //cout<<now<<" "<<res[y]<<" "<<sz[y]<<endl;
        return true;
    }
    
        
};


int main(){
    cin>>N>>M>>T;
    vector<P> p;
    REP(i,N+1)d[i]=114514,exist[i]=0;
    g.resize(N+1);
    REP(i,M){
        cin>>a[i]>>b[i]>>c[i];
        p.pb(make_pair(c[i],i));
        g[a[i]].pb(i);
        g[b[i]].pb(i);
    }
    sort(ALL(p));
    reverse(ALL(p));
    dijkstra();
    UnionFind uf(N);
    REP(i,M){
        int e=p[i].se;
        now=p[i].fi;
        int x=a[e],y=b[e];
        uf.unite(x,y);
    }
    LL res=0;
    FOR(i,1,N+1){
        int id=uf.find(i);
        chmax(res,uf.res[id]+uf.sz[id]*(uf.t[id]));
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 18448