#include <bits/stdc++.h>
template <class T>
inline void rd(T &x) {
  char c = getchar();
  x = 0;
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
}
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 5e3 + 10;
int d[N][N], n, m, v, mp[N][3], pre[N][N];
stack<int> s;
int main() {
  scanf("%d%d%d", &n, &m, &v);
  memset(d, inf, sizeof(d));
  for (int i = 1; i <= m; i++)
    for (int j = 0; j <= 2; j++) scanf("%d", &mp[i][j]);
  d[1][1] = 0;
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (d[i - 1][mp[j][0]] + mp[j][2] < d[i][mp[j][1]] &&
          d[i - 1][mp[j][0]] + mp[j][2] <= v) {
        d[i][mp[j][1]] = d[i - 1][mp[j][0]] + mp[j][2];
        pre[i][mp[j][1]] = mp[j][0];
      }
      if (d[i][n] <= v) ans = i;
    }
  }
  printf("%d\n", ans);
  for (int j = n; j; j = pre[ans--][j]) s.push(j);
  while (s.size()) {
    printf("%d ", s.top());
    s.pop();
  }
  return 0;
}
