#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 10;
pair<int, pair<int, int> > edge[N];
vector<int> vrtx;
long long dis[810][810];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    edge[i] = {c, {a, b}};
  }
  sort(edge, edge + m);
  for (int i = 0; i < k; i++) {
    int u = edge[i].second.first, v = edge[i].second.second;
    vrtx.push_back(u);
    vrtx.push_back(v);
  }
  sort(vrtx.begin(), vrtx.end());
  vrtx.resize(unique(vrtx.begin(), vrtx.end()) - vrtx.begin());
  for (int i = 0; i < (int)vrtx.size(); i++)
    for (int j = 0; j < (int)vrtx.size(); j++) {
      dis[i][j] = 1LL * 1e18;
      if (i == j) dis[i][j] = 0;
    }
  for (int i = 0; i < k; i++) {
    int u = edge[i].second.first, v = edge[i].second.second;
    u = lower_bound(vrtx.begin(), vrtx.end(), u) - vrtx.begin();
    v = lower_bound(vrtx.begin(), vrtx.end(), v) - vrtx.begin();
    dis[u][v] = edge[i].first;
    dis[v][u] = edge[i].first;
  }
  for (int i = 0; i < (int)vrtx.size(); i++)
    for (int j = 0; j < (int)vrtx.size(); j++)
      for (int k = 0; k < (int)vrtx.size(); k++) {
        if (dis[j][k] > dis[j][i] + dis[i][k])
          dis[j][k] = dis[j][i] + dis[i][k];
      }
  vector<long long> dists;
  for (int i = 0; i < (int)vrtx.size(); i++)
    for (int j = i + 1; j < (int)vrtx.size(); j++) {
      dists.push_back(dis[i][j]);
    }
  sort(dists.begin(), dists.end());
  cout << dists[k - 1] << endl;
  return 0;
}
