#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 7;
const long long INF = N * 1e9;
vector<long long> dijkstra(int s, vector<vector<pair<int, long long>>> edges) {
  int n = edges.size();
  vector<long long> d(n, INF);
  priority_queue<pair<int, long long>, vector<pair<int, long long>>,
                 greater<pair<int, long long>>>
      pq;
  while (!pq.empty()) pq.pop();
  d[s] = 0;
  pq.push(pair<int, long long>(d[s], s));
  while (!pq.empty()) {
    pair<int, long long> pqt = pq.top();
    pq.pop();
    int x = pqt.second;
    for (pair<int, long long> e : edges[x]) {
      int y = e.first;
      long long len = e.second;
      long long nw = d[x] + len;
      if (nw < d[y]) {
        d[y] = nw;
        pq.push(pair<int, long long>(nw, y));
      }
    }
  }
  return d;
}
int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  vector<pair<long long, pair<int, long long>>> edges;
  edges.clear();
  vector<pair<int, long long>> ve[N];
  for (int i = 0; i < m; ++i) {
    int x, y;
    long long w;
    scanf("%d %d %lld", &x, &y, &w);
    --x;
    --y;
    edges.push_back(make_pair(w, pair<int, long long>(x, y)));
    ve[x].push_back(pair<int, long long>(y, w));
  }
  sort(edges.begin(), edges.end());
  vector<int> v;
  v.clear();
  for (int i = 0; i < min(k, m); ++i) {
    int x = edges[i].second.first;
    int y = edges[i].second.second;
    v.push_back(x);
    v.push_back(y);
  }
  sort(v.begin(), v.end());
  auto it = unique(v.begin(), v.end());
  v.resize(it - v.begin());
  map<int, int> id;
  id.clear();
  for (int i = 0; i < v.size(); ++i) id[v[i]] = i;
  vector<vector<pair<int, long long>>> e(v.size());
  for (int i = 0; i < v.size(); ++i) {
    for (pair<int, long long> x : ve[v[i]]) {
      int y = x.first;
      long long w = x.second;
      if (id.count(y)) {
        e[i].push_back(pair<int, long long>(id[y], w));
        e[id[y]].push_back(pair<int, long long>(i, w));
      }
    }
  }
  vector<long long> len;
  len.clear();
  for (int i = 0; i < v.size(); ++i) {
    vector<long long> d = dijkstra(i, e);
    for (int j = i + 1; j < v.size(); ++j) {
      len.push_back(d[j]);
    }
  }
  sort(len.begin(), len.end());
  printf("%lld\n", len[k - 1]);
  return 0;
}
