#include <bits/stdc++.h>
using namespace std;
const int N = 200005, M = 200005, P = 1005;
int n, m, kk, mp[N], idx;
struct Node {
  int uu, vv, ww;
};
Node e[N];
long long dis[P][P];
int main() {
  scanf("%d%d%d", &n, &m, &kk);
  for (int i = 1; i <= m; i++) {
    int t1, t2, t3;
    cin >> t1 >> t2 >> t3;
    e[i] = {t1, t2, t3};
  }
  sort(e + 1, e + m + 1, [](Node a, Node b) { return a.ww < b.ww; });
  m = min(m, kk);
  for (int i = 1; i <= m; i++) {
    if (!mp[e[i].uu]) mp[e[i].uu] = ++idx;
    if (!mp[e[i].vv]) mp[e[i].vv] = ++idx;
    e[i].uu = mp[e[i].uu];
    e[i].vv = mp[e[i].vv];
  }
  n = idx;
  memset(dis, 63, sizeof(dis));
  for (int i = 1; i <= m; i++)
    dis[e[i].uu][e[i].vv] = dis[e[i].vv][e[i].uu] = e[i].ww;
  for (int i = 1; i <= n; i++) dis[i][i] = 0;
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        if (dis[i][j] > dis[i][k] + dis[k][j])
          dis[i][j] = dis[i][k] + dis[k][j];
  vector<long long> ans;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) ans.push_back(dis[i][j]);
  sort(ans.begin(), ans.end());
  cout << ans[kk - 1] << endl;
  return 0;
}
