1 #define IO std::ios::sync_with_stdio(0)
2 #include <bits/stdc++.h>
3 using namespace std;
4 #define mk make_pair
5 #define pb push_back
6 const int inf=2147483647;
7 const int N=1e5+10;
8
9 struct node{
10 int u,w;
11 bool operator <(const node&p)const{
12 return w>p.w;
13 }
14 };
15
16 vector<int>g[N],d[N];
17 int dis[N];
18 int n,m,s;
19 int vis[N];
20
21 void dij(){
22 priority_queue<node>q;
23 fill(dis+1,dis+n+1,inf);
24 dis[1]=0;
25 vis[1]=1;
26 q.push(node{1,0});
27 while(!q.empty()){
28 node now=q.top();
29 q.pop();
30 int u=now.u;
31 if(now.w!=dis[u])continue;//优化,如果已经更新了与u相连的点通过u点到起点的距离那么无需再更新
32 for(int i=0;i<g[u].size();i++){
33 int v=g[u][i];
34 if(!vis[v]&&dis[u]+d[u][i]<dis[v]){
35 vis[v]=1;
36 dis[v]=dis[u]+d[u][i];
37 q.push(node{v,dis[v]});
38 }
39 }
40 }
41 }
42 int main(){
43 IO;
44 cin>>n>>m>>s;
45 for(int i=1;i<=m;i++){
46 int u,v,w;
47 cin>>u>>v>>w;
48 if(w<s)continue;
49 if(m>400000)continue;
50 g[u].pb(v);
51 g[v].pb(u);
52 d[u].pb(1);
53 d[v].pb(1);
54 }
55 dij();
56 if(dis[n]<inf)cout<<dis[n]<<endl;
57 else cout<<-1<<endl;
58 }