#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
bool used[5050];
vector<pair<int, int> > inp[5050];
int out[5050];
pair<int, int> dp[5050][5050];
vector<int> tropsort;
vector<pair<int, int> > wa[5050];
int inTS[5050];
void tsort(int b) {
  used[b] = true;
  for (int i = 0; i < inp[b].size(); i++) {
    if (!used[inp[b][i].first]) {
      tsort(inp[b][i].first);
    }
  }
  tropsort.push_back(b);
}
int main() {
  int n, m, t;
  scanf("%d%d%d", &n, &m, &t);
  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    inp[x - 1].push_back(make_pair(y - 1, z));
  }
  for (int i = 0; i < n; i++)
    if (!used[i]) tsort(i);
  reverse(tropsort.begin(), tropsort.end());
  for (int i = 0; i < n; i++) inTS[tropsort[i]] = i;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < inp[i].size(); j++) {
      int w = inTS[i], v = inTS[inp[i][j].first];
      wa[w].push_back(make_pair(v, inp[i][j].second));
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j].first = t + 100;
    }
  }
  dp[inTS[0]][0] = make_pair(0, -1);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < wa[i].size(); j++) {
      for (int k = 0; k < i + 1; k++) {
        if (dp[i][k].first + wa[i][j].second <
            dp[wa[i][j].first][k + 1].first) {
          dp[wa[i][j].first][k + 1] =
              make_pair(dp[i][k].first + wa[i][j].second, i);
        }
      }
    }
  }
  int ans = -1;
  for (int i = 0; i < n; i++) {
    if (dp[inTS[n - 1]][i].first <= t) {
      ans = max(ans, i);
    }
  }
  int l = inTS[n - 1];
  out[ans] = tropsort[l];
  for (int i = ans - 1; i >= 0; i--) {
    l = dp[l][i + 1].second;
    out[i] = tropsort[l];
  }
  cout << ans + 1 << endl;
  for (int i = 0; i < ans + 1; i++) cout << out[i] + 1 << " ";
  return 0;
}
