#include<bits/stdc++.h>
#define xx first
#define yy second
#define all(a) a.begin(), a.end()
#define vsort(v) sort(all(v))
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define clr(a,k) memset(a,k,sizeof a)
#define bclr(b) memset(b,false,sizeof b)
#define fr(i, a) for(i = 0; i < a; i++)
#define frr(i,a) for(i = a - 1; i >= 0, i--)
#define LL long long
#define PB push_back
#define mp make_pair
///***** bit *****///
#define check_bit(a, b) (a&(1<<b))
#define set_bit(a, b) (a|(1<<b))
#define total_bit(a) __builtin_popcount(a)
///***** Input / Output *****///
#define s1(a) scanf("%d", &a)
#define s2(a, b) scanf("%d %d", &a, &b)
#define s3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define p1(a) printf("%d", a)
#define p2(a, b) printf("%d %d", a, b)
#define p3(a, b, c) printf("%d %d %d", a, b, c)
#define MOD 1000000007
#define MAX 100009
using namespace std;
int n, m, s;
struct Z
{
int v, pre;
LL w;
Z() {}
Z(int ___, int _, LL __)
{
pre = ___;
v = _;
w = __;
}
bool operator < (const Z& A) const
{
return w > A.w;
}
};
map< pair< pair<int, int> , LL> , bool>M;
vector<Z>V[MAX];
LL dist[MAX];
LL l;
bool vis[100009];
LL cost[100009];
int DIJKSTRA()
{
for(int i = 0; i <= n; i++)
dist[i] = INT_MAX, vis[i] = false;
Z tmp;
tmp.v = s;
tmp.w = 0;
priority_queue<Z>PQ;
PQ.push(tmp);
int cnt = 0;
while(!PQ.empty())
{
tmp = PQ.top();
PQ.pop();
int cn = tmp.v;
int pre = tmp.pre;
LL cc = tmp.w;
if(vis[cn]) continue;
vis[cn] = true;
if(cc >= l) continue;
dist[cn] = cc;
int sz = V[cn].size();
for(int i = 0; i < sz; i++)
{
int adjn = V[cn][i].v;
LL adjc = V[cn][i].w;
if(adjn == pre) continue;
if(adjc + cc == l)
{
pair < pair<int, int>, LL> P = mp(mp(adjn, adjn), 0);
if(!M[P])
{
M[P] = true;
cnt++;
}
continue;
}
else if(adjc + cc > l)
{
LL len = l - cc;
pair < pair<int, int>, LL> P = mp(mp(cn, adjn), len);
if(M[P]) continue;
LL rest = adjc - len;
if(rest + cost[adjn] >= l)
{
M[P] = true;
pair < pair<int, int>, LL> P1 = mp(mp(adjn, cn), rest);
M[P1] = true;
cnt++;
}
continue;
}
if(!vis[adjn] && adjc + cc < dist[adjn])
{
tmp.v = adjn;
tmp.w = cc + adjc;
tmp.pre = cn;
PQ.push(tmp);
}
}
}
return cnt;
}
void DIJKSTRA_first()
{
for(int i = 0; i <= n; i++)
cost[i] = INT_MAX, vis[i] = false;
priority_queue<Z>PQ;
Z tmp;
tmp.v = s;
tmp.w = 0;
PQ.push(tmp);
while(!PQ.empty())
{
Z top = PQ.top();
PQ.pop();
int cn = top.v;
LL cc = top.w;
if(vis[cn]) continue;
cost[cn] = cc;
vis[cn] = true;
int sz = V[cn].size();
for(int i = 0; i < sz; i++)
{
int adjn = V[cn][i].v;
LL adjc = V[cn][i].w + cc;
if(!vis[adjn] && adjc < cost[adjn])
{
tmp.v = adjn;
tmp.w = adjc;
cost[adjn] = adjc;
PQ.push(tmp);
}
}
}
}
int main()
{
int tc,cs=1,i,j,k, v, u;
LL w;
cin>>n>>m>>s;
M.clear();
fr(i, m)
{
cin>>u>>v>>w;
V[u].PB(Z(0,v, w));
V[v].PB(Z(0,u, w));
}
cin>>l;
DIJKSTRA_first();
int res = DIJKSTRA();
cout<<res<<endl;
for(i = 0; i <= n; i++)
V[i].clear();
return 0;
}
/*
//
4 6 1
1 2 1
1 3 3
2 3 1
2 4 1
3 4 1
1 4 2
1
*/
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCiNkZWZpbmUgeHggZmlyc3QKI2RlZmluZSB5eSBzZWNvbmQKI2RlZmluZSBhbGwoYSkgYS5iZWdpbigpLCBhLmVuZCgpCiNkZWZpbmUgdnNvcnQodikgc29ydChhbGwodikpCiNkZWZpbmUgVU5JUVVFKGEpICBzb3J0KGFsbChhKSk7IGEuZXJhc2UodW5p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AgICAgICAgcHJlID0gX19fOwogICAgICAgIHYgPSBfOwogICAgICAgIHcgPSBfXzsKICAgIH0KICAgIGJvb2wgb3BlcmF0b3IgPCAoY29uc3QgWiYgQSkgY29uc3QKICAgIHsKICAgICAgICByZXR1cm4gdyA+IEEudzsKICAgIH0KfTsKCm1hcDwgcGFpcjwgcGFpcjxpbnQsIGludD4gLCBMTD4gLCBib29sPk07CnZlY3RvcjxaPlZbTUFYXTsKTEwgZGlzdFtNQVhdOwpMTCBsOwoKYm9vbCB2aXNbMTAwMDA5XTsKTEwgY29zdFsxMDAwMDldOwoKaW50IERJSktTVFJBKCkKewogICAgZm9yKGludCBpID0gMDsgaSA8PSBuOyBpKyspCiAgICAgICAgZGlzdFtpXSA9IElOVF9NQVgsIHZpc1tpXSA9IGZhbHNlOwoKICAgIFogdG1wOwogICAgdG1wLnYgPSBzOwogICAgdG1wLncgPSAwOwogICAgcHJpb3JpdHlfcXVldWU8Wj5QUTsKICAgIFBRLnB1c2godG1wKTsKICAgIGludCBjbnQgPSAwOwoKICAgIHdoaWxlKCFQUS5lbXB0eSgpKQogICAgewogICAgICAgIHRtcCA9IFBRLnRvcCgpOwogICAgICAgIFBRLnBvcCgpOwogICAgICAgIGludCBjbiA9IHRtcC52OwogICAgICAgIGludCBwcmUgPSB0bXAucHJlOwogICAgICAgIExMIGNjID0gdG1wLnc7CiAgICAgICAgaWYodmlzW2NuXSkgY29udGludWU7CiAgICAgICAgdmlzW2NuXSA9IHRydWU7CiAgICAgICAgaWYoY2MgPj0gbCkgY29udGludWU7CgogICAgICAgIGRpc3RbY25dID0gY2M7CgogICAgICAgIGludCBzeiA9IFZbY25dLnNpemUoKTsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgc3o7IGkrKykKICAgICAgICB7CiAgICAgICAgICAgIGludCBhZGpuID0gVltjbl1baV0udjsKICAgICAgICAgICAgTEwgYWRqYyA9IFZbY25dW2ldLnc7CiAgICAgICAgICAgIGlmKGFkam4gPT0gcHJlKSBjb250aW51ZTsKICAgICAgICAgICAgaWYoYWRqYyArIGNjID09IGwpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHBhaXIgPCBwYWlyPGludCwgaW50PiwgTEw+IFAgPSBtcChtcChhZGpuLCBhZGpuKSwgMCk7CiAgICAgICAgICAgICAgICBpZighTVtQXSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBNW1BdID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICBjbnQrKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYoYWRqYyArIGNjID4gbCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgTEwgbGVuID0gbCAtIGNjOwogICAgICAgICAgICAgICAgcGFpciA8IHBhaXI8aW50LCBpbnQ+LCBMTD4gUCA9IG1wKG1wKGNuLCBhZGpuKSwgbGVuKTsKICAgICAgICAgICAgICAgIGlmKE1bUF0pIGNvbnRpbnVlOwoKICAgICAgICAgICAgICAgIExMIHJlc3QgPSBhZGpjIC0gbGVuOwogICAgICAgICAgICAgICAgaWYocmVzdCArIGNvc3RbYWRqbl0gPj0gbCkKICAgICAgICAgICAgICAgIHsKCiAgICAgICAgICAgICAgICAgICAgTVtQXSA9IHRydWU7CgogICAgICAgICAgICAgICAgICAgIHBhaXIgPCBwYWlyPGludCwgaW50PiwgTEw+IFAxID0gbXAobXAoYWRqbiwgY24pLCByZXN0KTsKICAgICAgICAgICAgICAgICAgICBNW1AxXSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgY250Kys7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZighdmlzW2Fkam5dICYmIGFkamMgKyBjYyA8IGRpc3RbYWRqbl0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHRtcC52ID0gYWRqbjsKICAgICAgICAgICAgICAgIHRtcC53ID0gY2MgKyBhZGpjOwogICAgICAgICAgICAgICAgdG1wLnByZSA9IGNuOwogICAgICAgICAgICAgICAgUFEucHVzaCh0bXApOwogICAgICAgICAgICB9CgogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBjbnQ7Cn0KCgoKCnZvaWQgRElKS1NUUkFfZmlyc3QoKQp7CiAgICBmb3IoaW50IGkgPSAwOyBpIDw9IG47IGkrKykKICAgICAgICBjb3N0W2ldID0gSU5UX01BWCwgdmlzW2ldID0gZmFsc2U7CgogICAgcHJpb3JpdHlfcXVldWU8Wj5QUTsKICAgIFogdG1wOwogICAgdG1wLnYgPSBzOwogICAgdG1wLncgPSAwOwogICAgUFEucHVzaCh0bXApOwoKICAgIHdoaWxlKCFQUS5lbXB0eSgpKQogICAgewogICAgICAgIFogdG9wID0gUFEudG9wKCk7CiAgICAgICAgUFEucG9wKCk7CgogICAgICAgIGludCBjbiA9IHRvcC52OwogICAgICAgIExMIGNjID0gdG9wLnc7CgogICAgICAgIGlmKHZpc1tjbl0pIGNvbnRpbnVlOwogICAgICAgIGNvc3RbY25dID0gY2M7CiAgICAgICAgdmlzW2NuXSA9IHRydWU7CgogICAgICAgIGludCBzeiA9IFZbY25dLnNpemUoKTsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgc3o7IGkrKykKICAgICAgICB7CiAgICAgICAgICAgIGludCBhZGpuID0gVltjbl1baV0udjsKICAgICAgICAgICAgTEwgYWRqYyA9IFZbY25dW2ldLncgKyBjYzsKICAgICAgICAgICAgaWYoIXZpc1thZGpuXSAmJiBhZGpjIDwgY29zdFthZGpuXSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdG1wLnYgPSBhZGpuOwogICAgICAgICAgICAgICAgdG1wLncgPSBhZGpjOwogICAgICAgICAgICAgICAgY29zdFthZGpuXSA9IGFkamM7CiAgICAgICAgICAgICAgICBQUS5wdXNoKHRtcCk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0KCgoKCgppbnQgbWFpbigpCnsKICAgIGludCB0Yyxjcz0xLGksaixrLCB2LCB1OwogICAgTEwgdzsKICAgIGNpbj4+bj4+bT4+czsKICAgIE0uY2xlYXIoKTsKCiAgICBmcihpLCBtKQogICAgewogICAgICAgIGNpbj4+dT4+dj4+dzsKICAgICAgICBWW3VdLlBCKFooMCx2LCB3KSk7CiAgICAgICAgVlt2XS5QQihaKDAsdSwgdykpOwogICAgfQoKICAgIGNpbj4+bDsKICAgIERJSktTVFJBX2ZpcnN0KCk7CiAgICBpbnQgcmVzID0gRElKS1NUUkEoKTsKICAgIGNvdXQ8PHJlczw8ZW5kbDsKCiAgICBmb3IoaSA9IDA7IGkgPD0gbjsgaSsrKQogICAgICAgIFZbaV0uY2xlYXIoKTsKICAgIHJldHVybiAwOwp9CgovKgovLwoKNCA2IDEKMSAyIDEKMSAzIDMKMiAzIDEKMiA0IDEKMyA0IDEKMSA0IDIKMQoKCiovCg==