#include <set>
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;++i)
#define pb push_back
#define mp make_pair
const int INF=1000000000;
const int dd=5000,nn=5000000;
int other[nn],next[nn],g[dd],va[nn],di[dd],vh[dd],dis[dd],pre[dd],his[dd];
int vv[nn],f[3100][3100],q[nn];
vector<int> E[dd],v[dd];
int n,m,S,T,es,sum,flow;
void dfs(int r,int y)
{
	if (vv[y]) return;
	vv[y]=1;
	for (int i=0;i<E[y].size();++i)
	{
		int j=E[y][i];
		if (vv[j]) continue;
		f[r][j]=max(f[r][y],v[y][i]);
		dfs(r,j);
	}
}
void insert(int x,int y,int z)
{
    other[++es]=y;next[es]=g[x];g[x]=es;va[es]=z;
    other[++es]=x;next[es]=g[y];g[y]=es;va[es]=0;
}
void sap()
{
    rep(i,S,T) di[i]=g[i],dis[i]=0,vh[i]=0;
    vh[T+1]=0;
    vh[0]=T-S+1;
    flow=0;int aug=INF,i=S;
    while (dis[S]<T-S+1)
    {
        his[i]=aug;bool flag=0;
        for (int p=di[i];p;p=next[p])
        {
            if (va[p]<=0) continue;
            int j=other[p];
            if (dis[i] == dis[j]+1)
            {
                aug=min(aug,va[p]);
                pre[j]=p;
                flag=1;
                di[i]=p;
                i=j;
                if (i==T)
                {
                    flow+=aug;
                    while (i!=S)
                    {
                        va[pre[i]]-=aug;
                        va[pre[i]^1]+=aug;
                        i=other[pre[i]^1];
                    }
                    aug=INF;
                }
                break;
            }
        }
        if (flag) continue;
        int minn=T-S,j1=0;
        for (int p=g[i];p;p=next[p])
            if (va[p]>0&&dis[other[p]]<minn) minn=dis[other[p]],j1=p;
        --vh[dis[i]];
        if (!vh[dis[i]]) break;
        dis[i]=minn+1;
        ++vh[dis[i]];
        di[i]=j1;
        if (i!=S) i=other[pre[i]^1],aug=his[i];
    }
}
bool check(int mid)
{
	S=0;T=2*n+1;es=1;
	rep(i,S,T) g[i]=0;
	rep(i,1,n) insert(S,i,q[i]);
	rep(i,1,n) insert(n+i,T,1);
	rep(i,1,n)
	rep(j,1,n)
		if (f[j][i]>=mid) insert(i,n+j,1);
	flow=0;
	sap();
	return flow>=n;
}
int main()
{
	scanf("%d",&n);
	int mm=0;
	rep(i,1,n-1)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		mm=max(mm,z);
		E[x].pb(y);v[x].pb(z);
		E[y].pb(x);v[y].pb(z);
	}
	rep(i,1,n) scanf("%d",&q[i]);
	rep(i,1,n)
	{
		rep(j,1,n) vv[j]=0;
		dfs(i,i);
	}
	int l=0,r=mm;
	while (l+1 < r)
	{
		int mid=l+r>>1;
		if (check(mid)) l=mid; else r=mid-1;
	}
	if (check(l+1)) l++;
	printf("%d\n",l);
	return 0;
}


#include <set>
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;++i)
#define pb push_back
#define mp make_pair
const int INF=1000000000;
const int dd=3100,nn=3000*3000*2+1;
int other[nn],next[nn],g[dd],va[nn],di[dd],vh[dd],dis[dd],pre[dd],his[dd];
int vv[dd],f[3100][3100],q[dd];
vector<int> E[dd],v[dd];
int n,m,S,T,es,sum,flow;
void dfs(int r,int y)
{
	if (vv[y]) return;
	vv[y]=1;
	for (int i=0;i<E[y].size();++i)
	{
		int j=E[y][i];
		if (vv[j]) continue;
		f[r][j]=max(f[r][y],v[y][i]);
		dfs(r,j);
	}
}
void insert(int x,int y,int z)
{
    other[++es]=y;next[es]=g[x];g[x]=es;va[es]=z;
    other[++es]=x;next[es]=g[y];g[y]=es;va[es]=0;
}
void sap()
{
    rep(i,S,T) di[i]=g[i],dis[i]=0,vh[i]=0;
    vh[T+1]=0;
    vh[0]=T-S+1;
    flow=0;int aug=INF,i=S;
    while (dis[S]<T-S+1)
    {
        his[i]=aug;bool flag=0;
        for (int p=di[i];p;p=next[p])
        {
            if (va[p]<=0) continue;
            int j=other[p];
            if (dis[i] == dis[j]+1)
            {
                aug=min(aug,va[p]);
                pre[j]=p;
                flag=1;
                di[i]=p;
                i=j;
                if (i==T)
                {
                    flow+=aug;
                    while (i!=S)
                    {
                        va[pre[i]]-=aug;
                        va[pre[i]^1]+=aug;
                        i=other[pre[i]^1];
                    }
                    aug=INF;
                }
                break;
            }
        }
        if (flag) continue;
        int minn=T-S,j1=0;
        for (int p=g[i];p;p=next[p])
            if (va[p]>0&&dis[other[p]]<minn) minn=dis[other[p]],j1=p;
        --vh[dis[i]];
        if (!vh[dis[i]]) break;
        dis[i]=minn+1;
        ++vh[dis[i]];
        di[i]=j1;
        if (i!=S) i=other[pre[i]^1],aug=his[i];
    }
}
bool check(int mid)
{
	S=0;T=2*n+1;es=1;
	rep(i,S,T) g[i]=0;
	rep(i,1,n) insert(S,i,q[i]);
	rep(i,1,n) insert(n+i,T,1);
	rep(i,1,n)
	rep(j,1,n)
		if (f[j][i]>=mid) insert(i,n+j,1);
	flow=0;
	sap();
	return flow>=n;
}
int main()
{
	scanf("%d",&n);
	int mm=0;
	rep(i,1,n-1)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		mm=max(mm,z);
		E[x].pb(y);v[x].pb(z);
		E[y].pb(x);v[y].pb(z);
	}
	rep(i,1,n) scanf("%d",&q[i]);
	rep(i,1,n)
	{
		rep(j,1,n) vv[j]=0;
		dfs(i,i);
	}
	int l=0,r=mm;
	while (l+1 < r)
	{
		int mid=l+r>>1;
		if (check(mid)) l=mid; else r=mid-1;
	}
	if (check(l+1)) l++;
	printf("%d\n",l);
	return 0;
}


#include <cstdio>
#include <algorithm>
#define rep(i,a,b) for (int i=a;i<=b;++i)
using namespace std;
const int nn=11000;
struct pp
{
	int x,y,z;
} e[nn];
int n,ans,sum,flag,f[nn],s[nn],c[nn];
int find(int x)
{
	if (f[x]==x) return x;
	return f[x]=find(f[x]);
}
bool cmp(const pp &x,const pp &y)
{
	return x.z<y.z;
}
void merge(int i)
{
	int fx=find(e[i].x),fy=find(e[i].y);
	s[fx]+=s[fy];
	c[fx]+=c[fy];
	f[fy]=fx;
	if (s[fx] > sum-c[fx]) flag=1;
}
int main()
{
	scanf("%d",&n);
	rep(i,1,n-1)
	{
		scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].z);
	}
	rep(i,1,n)
	{
		scanf("%d",&c[i]);
		s[i]=1;
		sum+=c[i];
		f[i]=i;
	}
	rep(i,1,n)
		if (sum-c[i] < s[i]) flag=1;
	sort(e+1,e+n,cmp);
	int j;
	if (!flag) ans=e[1].z;
	for (int i=1;i<n;)
	{
		if (flag) break;
		j=i-1;
		while (e[j+1].z==e[i].z)
			j++,merge(j);
		if (!flag) ans=max(ans,e[j+1].z);
		//printf(" %d\n",flag);
		i=j+1;
	}
	printf("%d\n",ans);
	return 0;
}


#include <set>
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;++i)
#define pb push_back
#define mp make_pair
const int INF=1000000000;
const int dd=3100,nn=3000*3000*2+1;
int other[nn],next[nn],g[dd],va[nn],di[dd],vh[dd],dis[dd],pre[dd],his[dd];
int vv[dd],f[3100][3100],q[dd];
vector<int> E[dd],v[dd];
int n,m,S,T,es,sum,flow;
void dfs(int r,int y)
{
	if (vv[y]) return;
	vv[y]=1;
	for (int i=0;i<E[y].size();++i)
	{
		int j=E[y][i];
		if (vv[j]) continue;
		f[r][j]=max(f[r][y],v[y][i]);
		dfs(r,j);
	}
}
void insert(int x,int y,int z)
{
    other[++es]=y;next[es]=g[x];g[x]=es;va[es]=z;
    other[++es]=x;next[es]=g[y];g[y]=es;va[es]=0;
}
void sap()
{
    rep(i,S,T) di[i]=g[i],dis[i]=0,vh[i]=0;
    vh[T+1]=0;
    vh[0]=T-S+1;
    flow=0;int aug=INF,i=S;
    while (dis[S]<T-S+1)
    {
        his[i]=aug;bool flag=0;
        for (int p=di[i];p;p=next[p])
        {
            if (va[p]<=0) continue;
            int j=other[p];
            if (dis[i] == dis[j]+1)
            {
                aug=min(aug,va[p]);
                pre[j]=p;
                flag=1;
                di[i]=p;
                i=j;
                if (i==T)
                {
                    flow+=aug;
                    if (flow>=n) return;
                    while (i!=S)
                    {
                        va[pre[i]]-=aug;
                        va[pre[i]^1]+=aug;
                        i=other[pre[i]^1];
                    }
                    aug=INF;
                }
                break;
            }
        }
        if (flag) continue;
        int minn=T-S,j1=0;
        for (int p=g[i];p;p=next[p])
            if (va[p]>0&&dis[other[p]]<minn) minn=dis[other[p]],j1=p;
        --vh[dis[i]];
        if (!vh[dis[i]]) break;
        dis[i]=minn+1;
        ++vh[dis[i]];
        di[i]=j1;
        if (i!=S) i=other[pre[i]^1],aug=his[i];
    }
}
bool check(int mid)
{
	S=0;T=2*n+1;es=1;
	rep(i,S,T) g[i]=0;
	rep(i,1,n) insert(S,i,q[i]);
	rep(i,1,n) insert(n+i,T,1);
	rep(i,1,n)
	rep(j,1,n)
		if (f[j][i]>=mid) insert(i,n+j,1);
	flow=0;
	sap();
	return flow>=n;
}
int main()
{
	scanf("%d",&n);
	int mm=0;
	rep(i,1,n-1)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		mm=max(mm,z);
		E[x].pb(y);v[x].pb(z);
		E[y].pb(x);v[y].pb(z);
	}
	rep(i,1,n) scanf("%d",&q[i]);
	rep(i,1,n)
	{
		rep(j,1,n) vv[j]=0;
		dfs(i,i);
	}
	int l=0,r=mm;
	while (l+1 < r)
	{
		int mid=l+r>>1;
		if (check(mid)) l=mid; else r=mid-1;
	}
	if (check(l+1)) l++;
	printf("%d\n",l);
	return 0;
}


#include <set>
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;++i)
#define pb push_back
#define mp make_pair
const int INF=1000000000;
const int dd=5000,nn=20000000;
int other[nn],next[nn],g[dd],va[nn],di[dd],vh[dd],dis[dd],pre[dd],his[dd];
int vv[nn],f[3100][3100],q[nn];
vector<int> E[dd],v[dd];
int n,m,S,T,es,sum,flow;
void dfs(int r,int y)
{
	if (vv[y]) return;
	vv[y]=1;
	for (int i=0;i<E[y].size();++i)
	{
		int j=E[y][i];
		if (vv[j]) continue;
		f[r][j]=max(f[r][y],v[y][i]);
		dfs(r,j);
	}
}
void insert(int x,int y,int z)
{
    other[++es]=y;next[es]=g[x];g[x]=es;va[es]=z;
    other[++es]=x;next[es]=g[y];g[y]=es;va[es]=0;
}
void sap()
{
    rep(i,S,T) di[i]=g[i],dis[i]=0,vh[i]=0;
    vh[T+1]=0;
    vh[0]=T-S+1;
    flow=0;int aug=INF,i=S;
    while (dis[S]<T-S+1)
    {
        his[i]=aug;bool flag=0;
        for (int p=di[i];p;p=next[p])
        {
            if (va[p]<=0) continue;
            int j=other[p];
            if (dis[i] == dis[j]+1)
            {
                aug=min(aug,va[p]);
                pre[j]=p;
                flag=1;
                di[i]=p;
                i=j;
                if (i==T)
                {
                    flow+=aug;
                    while (i!=S)
                    {
                        va[pre[i]]-=aug;
                        va[pre[i]^1]+=aug;
                        i=other[pre[i]^1];
                    }
                    aug=INF;
                }
                break;
            }
        }
        if (flag) continue;
        int minn=T-S,j1=0;
        for (int p=g[i];p;p=next[p])
            if (va[p]>0&&dis[other[p]]<minn) minn=dis[other[p]],j1=p;
        --vh[dis[i]];
        if (!vh[dis[i]]) break;
        dis[i]=minn+1;
        ++vh[dis[i]];
        di[i]=j1;
        if (i!=S) i=other[pre[i]^1],aug=his[i];
    }
}
bool check(int mid)
{
	S=0;T=2*n+1;es=1;
	rep(i,S,T) g[i]=0;
	rep(i,1,n) insert(S,i,q[i]);
	rep(i,1,n) insert(n+i,T,1);
	rep(i,1,n)
	rep(j,1,n)
		if (f[j][i]>=mid) insert(i,n+j,1);
	flow=0;
	sap();
	return flow>=n;
}
int main()
{
	scanf("%d",&n);
	int mm=0;
	rep(i,1,n-1)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		mm=max(mm,z);
		E[x].pb(y);v[x].pb(z);
		E[y].pb(x);v[y].pb(z);
	}
	rep(i,1,n) scanf("%d",&q[i]);
	rep(i,1,n)
	{
		rep(j,1,n) vv[j]=0;
		dfs(i,i);
	}
	int l=0,r=mm;
	while (l+1 < r)
	{
		int mid=l+r>>1;
		if (check(mid)) l=mid; else r=mid-1;
	}
	if (check(l+1)) l++;
	printf("%d\n",l);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,l,r) for (int i=l; i<=r; i++)
#define drep(i,r,l) for (int i=r; i>=l; i--)
#define mp make_pair
typedef long long ll;
const int N = 3008;
int n, fa[N], sz[N], sum[N], all, ans;
struct Edge
{
    int u, v, d;
    bool operator < (const Edge &b) const {return d < b.d;}
}L[N];
int find(int x)
{
    return x == fa[x] ? fa[x] : fa[x] = find(fa[x]);
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    scanf("%d", &n);
    rep(i, 1, n - 1)
    {
        scanf("%d%d%d", &L[i].u, &L[i].v, &L[i].d);
    }
    rep(i, 1, n) scanf("%d", &sum[i]), fa[i] = i, sz[i] = 1, all += sum[i];
    sort(L + 1, L + n);
    ans = L[1].d;
    rep(i, 1, n - 1)
    {
        int u = find(L[i].u), v = find(L[i].v);
        sz[u] += sz[v]; sum[u] += sum[v]; fa[v] = u;
        if (sz[u] + sum[u] > all) break;
        if (L[i].d != L[i + 1].d) ans = L[i + 1].d;
    }
    printf("%d\n", ans);
#ifndef ONLINE_JUDGE
    fclose(stdin); fclose(stdout);
#endif
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,l,r) for (int i=l; i<=r; i++)
#define drep(i,r,l) for (int i=r; i>=l; i--)
#define mp make_pair
typedef long long ll;
const int N = 3008;
int n, fa[N], sz[N], sum[N], all, ans;
struct Edge
{
    int u, v, d;
    bool operator < (const Edge &b) const {return d < b.d;}
}L[N];
int find(int x)
{
    return x == fa[x] ? fa[x] : fa[x] = find(fa[x]);
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    scanf("%d", &n);
    rep(i, 1, n - 1)
    {
        scanf("%d%d%d", &L[i].u, &L[i].v, &L[i].d);
    }
    rep(i, 1, n) scanf("%d", &sum[i]), fa[i] = i, sz[i] = 1, all += sum[i];
    sort(L + 1, L + n);
    rep(i, 1, n - 1)
    {
        int u = find(L[i].u), v = find(L[i].v);
        sz[u] += sz[v]; sum[u] += sum[v]; fa[v] = u;
        if (sz[u] + sum[u] > all) break;
        if (L[i].d != L[i + 1].d) ans = L[i + 1].d;
    }
    printf("%d\n", ans);
#ifndef ONLINE_JUDGE
    fclose(stdin); fclose(stdout);
#endif
    return 0;
}


#include <iostream>
#include <vector>
#define mp make_pair
#define pii pair<int, int>
#define SHN 1e9+7
using namespace std;
int n,m,k;
vector<pii> v[5010];
int d[5010][5010];
int res=SHN;
int dp(int x,int y)
{
	if (d[x][y]!=SHN) return d[x][y];
	if (!y)
	{
		if (x==n-1) d[x][y]=0;
		return d[x][y];
	}
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].first;
		int yi=v[x][i].second;
		if (dp(xi,y-1)+yi<d[x][y]) d[x][y]=dp(xi,y-1)+yi;
	}
	//cout <<x+1<<" "<<y+1<<" "<<d[x][y]<<"\n";
	return d[x][y];
}
void out(int x,int y)
{
	cout <<x+1<<" ";
	if (!y) return;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].first;
		int yi=v[x][i].second;
		if (d[xi][y-1]+yi==d[x][y])
		{
			out(xi,y-1);
			break;
		}
	}
}
int main()
{
	cin >>n>>m>>k;
	for (int i=0;i<m;i++)
	{
		int x,y,c;
		cin >>x>>y>>c;
		x--,y--;
		v[x].push_back(mp(y,c));
	}
	for (int i=0;i<n;i++) fill(d[i],d[i]+n,SHN);
	for (int i=n-1;i>0;i--)
	{
		if (dp(0,i)<=k)
		{
			cout <<i+1<<"\n";
			out(0,i);
			return 0;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int d[5010][5010];
int pre[5010][5010];
int n,m,t;
vector<PII> v[5010];
vector<int> tp;
bool visit[100010];
void dfs(int x)
{
	visit[x]=1;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].Fst;
		if (visit[xi]) continue;
		dfs(xi);
	}
	tp.push_back(x);
}
void out(int x,int y)
{
	if (y!=1) out(pre[x][y],y-1);
	cout <<x+1<<" ";
}
int main()
{
	cin >>n>>m>>t;
	for(int i=0;i<m;i++)
	{
		int x,y,z;
		cin >>x>>y>>z;
		x--,y--;
		v[x].push_back(MP(y,z));
		v[y].push_back(MP(x,z));
	}
	for (int i=0;i<n;i++) if (!visit[i]) dfs(i);
	reverse(tp.begin(),tp.end());
	for (int i=0;i<n;i++) fill(d[i],d[i]+n+1,1e9+7);
	d[0][1]=0;
	for (int i=0;i<n;i++)
	{
		int x=tp[i];
		for (int j=1;j<n;j++)
		{
			for (int k=0;k<v[x].size();k++)
			{
				int xi=v[x][k].Fst,yi=v[x][k].Snd;
				if (d[x][j]+yi<d[xi][j+1])
				{
					d[xi][j+1]=d[x][j]+yi;
					pre[xi][j+1]=x;
				}
			}
		}
	}
	for(int i=n;i>0;i--)
	{
		if (d[n-1][i]<=t)
		{
			cout <<i<<"\n";
			out(n-1,i);
			return 0;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m,T;
vector<PLL> v[5010];
ll d[5010][5010];
ll pre[5010][5010];
void out(int x,int y)
{
	if (x>1) out(x-1,pre[x][y]);
	cout <<y+1<<" ";
}
int main()
{
	cin >>n>>m>>T;
	for (int i=0;i<m;i++)
	{
		ll x,y,z;
		cin >>x>>y>>z;
		x--,y--;
		v[x].push_back(MP(y,z));
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<n;j++)
			d[i][j]=LSHN;
	}
	d[1][0]=0;
	for (int i=1;i<n-1;i++)
	{
		for (int x=0;x<n;x++)
		{
			for (int k=0;k<v[x].size();k++)
			{
				ll xi=v[x][k].F;
				ll yi=v[x][k].S;
				if (d[i+1][xi]>d[i][x]+yi)
				{
					d[i+1][xi]=d[i][x]+yi;
					pre[i+1][xi]=x;
				}
			}
		}
	}
	for (int i=n;i>=1;i--)
	{
		if (d[i][n-1]<=T)
		{
			cout <<i<<"\n";
			out(i,n-1);
			break;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#define pii pair<int, int>
#define mp make_pair
using namespace std;
int n,m,k;
vector<pii> v[5010];
pii d[5010][5010];
vector<int> vv;
bool visit[5010]={0};
void dfs(int x)
{
	visit[x]=1;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].first;
		if (!visit[xi]) dfs(xi);
	}
	vv.push_back(x);
}
void out(int x,int y)
{
	if (d[x][y].second!=-1) out(d[x][y].second,y-1);
	cout <<x+1<<" ";
}
int main()
{
	cin >>n>>m>>k;
	for (int i=0;i<m;i++)
	{
		int x,y,c;
		cin >>x>>y>>c;
		x--,y--;
		v[x].push_back(mp(y,c));
	}
	for (int i=0;i<n;i++) if (!visit[i]) dfs(i);
	reverse(vv.begin(),vv.end());
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<n;j++)
		{
			d[i][j]=mp(1e9+7,-1);
		}
	}
	d[0][0]=mp(0,-1);
	for (int i=0;i<n;i++)
	{
		int x=vv[i];
		for (int j=0;j<v[x].size();j++)
		{
			int xi=v[x][j].first;
			int yi=v[x][j].second;
			for (int k=0;k<n;k++)
			    d[xi][k+1]=min(d[xi][k+1],mp(d[x][k].first+yi,x));
		}
	}
	for (int i=n-1;i>=0;i--)
	{
		if (d[n-1][i].first<=k)
		{
			cout <<i+1<<"\n";
			out(n-1,i);
			return 0;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m,T;
vector<PII> v[5010];
int d[5010][5010];
int r;
int dp(int x,int y)
{
	if (y==1) return x==n-1 ? 0 : SHN+7;
	if (d[x][y]!=SHN+7) return d[x][y];
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].F;
		int yi=v[x][i].S;
		d[x][y]=min(d[x][y],dp(xi,y-1)+yi);
	}
	return d[x][y];
}
void out(int x,int y)
{
	cout <<x+1<<" ";
	if (y==1) return;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].F;
		int yi=v[x][i].S;
		if (d[x][y]==d[xi][y-1]+yi)
		{
			out(xi,y-1);
			break;
		}
	}
}
int main()
{
	cin >>n>>m>>T;
	for (int i=0;i<m;i++)
	{
		int x,y,z;
		cin >>x>>y>>z;
		x--,y--;
		v[x].push_back(MP(y,z));
	}
	for (int i=0;i<n;i++)
	{
		for (int j=1;j<=n;j++)
			d[i][j]=1e9+7;
	}
	d[n-1][1]=0;
	for (int i=n;i>1;i--)
	{
		if (dp(0,i)<=T)
		{
			r=i;
			break;
		}
	}
	cout <<r<<"\n";
	out(0,r);
	return 0;
}


#include <iostream>
#include <vector>
#define mp make_pair
#define pii pair<int, int>
#define SHN 1e9+7
using namespace std;
int n,m,k;
vector<pii> v[5010];
int d[5010][5010];
int res=SHN;
int dp(int x,int y)
{
	if (d[x][y]!=SHN) return d[x][y];
	if (!y)
	{
		if (x==n-1) d[x][y]=0;
		return d[x][y];
	}
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].first;
		int yi=v[x][i].second;
		if (dp(xi,y-1)+yi<d[x][y]) d[x][y]=dp(xi,y-1)+yi;
	}
	//cout <<x+1<<" "<<y+1<<" "<<d[x][y]<<"\n";
	return d[x][y];
}
void out(int x,int y)
{
	cout <<x+1<<" ";
	if (!y) return;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].first;
		int yi=v[x][i].second;
		if (d[xi][y-1]+yi==d[x][y])
		{
			out(xi,y-1);
			break;
		}
	}
}
int main()
{
	cin >>n>>m>>k;
	for (int i=0;i<m;i++)
	{
		int x,y,c;
		cin >>x>>y>>c;
		x--,y--;
		v[x].push_back(mp(y,c));
	}
	for (int i=0;i<n;i++) fill(d[i],d[i]+n,SHN);
	for (int i=0;i<n;i++) if (dp(0,i)<=k) res=i;
	cout <<res+1<<"\n";
	out(0,res);
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int d[5010][5010];
int pre[5010][5010];
int n,m,t;
vector<PII> v[5010];
vector<int> tp;
bool visit[100010];
void dfs(int x)
{
	visit[x]=1;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].Fst;
		if (visit[xi]) continue;
		dfs(xi);
	}
	tp.push_back(x);
}
void out(int x,int y)
{
	if (y!=1) out(pre[x][y],y-1);
	cout <<x+1<<" ";
}
int main()
{
	cin >>n>>m>>t;
	for(int i=0;i<m;i++)
	{
		int x,y,z;
		cin >>x>>y>>z;
		x--,y--;
		v[x].push_back(MP(y,z));
	}
	for (int i=0;i<n;i++) if (!visit[i]) dfs(i);
	reverse(tp.begin(),tp.end());
	for (int i=0;i<n;i++) fill(d[i],d[i]+n+1,1e9+7);
	d[0][1]=0;
	for (int i=0;i<n;i++)
	{
		int x=tp[i];
		for (int j=1;j<n;j++)
		{
			for (int k=0;k<v[x].size();k++)
			{
				int xi=v[x][k].Fst,yi=v[x][k].Snd;
				if (d[x][j]+yi<d[xi][j+1])
				{
					d[xi][j+1]=d[x][j]+yi;
					pre[xi][j+1]=x;
				}
			}
		}
	}
	for(int i=n;i>0;i--)
	{
		if (d[n-1][i]<=t)
		{
			cout <<i<<"\n";
			out(n-1,i);
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pii pair<int, int>
#define SHN 1e9+7
using namespace std;
int n,m,k;
vector<pii> v[5010];
int d[5010][5010];
int par[5010][5010];
int res=SHN;
int dp(int x,int y)
{
	if (d[x][y]!=SHN) return d[x][y];
	if (!y)
	{
		if (x==n-1) d[x][y]=0;
		return d[x][y];
	}
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].first;
		int yi=v[x][i].second;
		if (dp(xi,y-1)+yi<d[x][y])
		{
			par[x][y]=xi;
			d[x][y]=dp(xi,y-1)+yi;
		}
	}
	//cout <<x+1<<" "<<y+1<<" "<<d[x][y]<<"\n";
	return d[x][y];
}
void out(int x,int y)
{
	cout <<x+1<<" ";
	if (y) out(par[x][y],y-1);
}
int main()
{
	cin >>n>>m>>k;
	for (int i=0;i<m;i++)
	{
		int x,y,c;
		cin >>x>>y>>c;
		x--,y--;
		v[x].push_back(mp(y,c));
	}
	memset(d,SHN,sizeof(d));
	for (int i=n-1;i>0;i--)
	{
		if (dp(0,i)<=k)
		{
			cout <<i+1<<"\n";
			out(0,i);
			return 0;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m,T;
vector< vector<PII> > v;
int d[5010][5010],pre[5010][5010];
int r;
vector<int> vr;
int main()
{
	cin >>n>>m>>T;
	v.resize(n);
	for (int i=0;i<m;i++)
	{
		int x,y,z;
		cin >>x>>y>>z;
		x--,y--;
		v[x].push_back(MP(y,z));
	}
	for (int i=1;i<=n;i++) fill(d[i],d[i]+n,T+7);
	d[1][0]=0;
	for (int i=1;i<n;i++)
	{
		for (int x=0;x<n;x++)
		{
			if (d[i][x]==T+7) continue;
			for (int j=0;j<v[x].size();j++)
			{
				int xi=v[x][j].F;
				int yi=v[x][j].S;
				if (d[i+1][xi]>d[i][x]+yi)
				{
					d[i+1][xi]=d[i][x]+yi;
					pre[i+1][xi]=x;
				}
			}
		}
	}
	for (int i=n;i>0;i--)
	{
		if (d[i][n-1]<=T)
		{
			r=i;
			break;
		}
	}
	cout <<r<<"\n";
	int x=n-1;
	vr.push_back(x+1);
	while (x)
	{
		x=pre[r--][x];
		vr.push_back(x+1);
	}
	reverse(vr.begin(),vr.end());
	for (int i=0;i<vr.size();i++) cout <<vr[i]<<" ";
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m,T;
vector<PII> v[5001],vi[5001];
int d[5001][5001];
void out(int x,int y)
{
	//cout <<x<<" "<<y<<" ####\n";
	if (x>1)
	{
		for (int i=0;i<vi[y].size();i++)
		{
			int xi=vi[y][i].F;
			int yi=vi[y][i].S;
			if (d[x][y]==d[x-1][xi]+yi)
			{
				out(x-1,xi);
				break;
			}
		}
	}
	cout <<y+1<<" ";
}
int main()
{
	cin >>n>>m>>T;
	for (int i=0;i<m;i++)
	{
		int x,y,z;
		cin >>x>>y>>z;
		x--,y--;
		v[x].push_back(MP(y,z));
		vi[y].push_back(MP(x,z));
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<n;j++)
			d[i][j]=SHN+7;
	}
	d[1][0]=0;
	for (int i=1;i<n-1;i++)
	{
		for (int x=0;x<n;x++)
		{
			for (int k=0;k<v[x].size();k++)
			{
				int xi=v[x][k].F;
				int yi=v[x][k].S;
				d[i+1][xi]=min(d[i+1][xi],d[i][x]+yi);
			}
		}
	}
	for (int i=n;i>=1;i--)
	{
		if (d[i][n-1]<=T)
		{
			cout <<i<<"\n";
			out(i,n-1);
			break;
		}
	}
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m,T;
vector< vector<PII> > v;
PII d[5010][5010];
bool visit[5010];
vector<int> tp;
void dfs(int x)
{
	visit[x]=1;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].F;
		if (!visit[xi]) dfs(xi);
	}
	tp.push_back(x);
}
void tpsort()
{
	for (int i=0;i<n;i++)
	{
		if (visit[i]) continue;
		dfs(i);
	}
	reverse(tp.begin(),tp.end());
}
void out(int x,int y)
{
	if (x) out(d[x][y].S,y-1);
	cout <<x+1<<" ";
}
int main()
{
	cin >>n>>m>>T;
	v.resize(n);
	for (int i=0;i<m;i++)
	{
		int x,y,z;
		cin >>x>>y>>z;
		x--,y--;
		v[x].push_back(MP(y,z));
	}
	tpsort();
	for (int i=0;i<n;i++) fill(d[i],d[i]+n+1,MP(T+7,-1));
	d[0][1]=MP(0,-1);
	for (int i=0;i<n;i++)
	{
		int x=tp[i];
		for (int j=1;j<n;j++)
		{
			if (d[x][j].F==T+7) continue;
			for (int k=0;k<v[x].size();k++)
			{
				int xi=v[x][k].F;
				int yi=v[x][k].S;
				d[xi][j+1]=min(d[xi][j+1],MP(d[x][j].F+yi,x));
			}
		}
	}
	for (int i=n;i>0;i--)
	{
		if (d[n-1][i].F<=T)
		{
			cout <<i<<"\n";
			out(n-1,i);
			break;
		}
	}
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <map>
#include <stack>
#include <string>
#include <vector>
#ifndef __INCLUDE_COMMON_H
#define __INCLUDE_COMMON_H
#include <algorithm>
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define max3(a, b, c) std::max(std::max((a),(b)), (c))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(_i, _n) for ((_i) = 0; (_i) < (_n); (_i) += 1)
#define fore(_i, _n) for ((_i) = 0; (_i) <= (_n); (_i) += 1)
#define forr(_i, _s, _e) for((_i) = (_s); (_i) < (_e); (_i) += 1)
#define forre(_i, _s, _e) for((_i) = (_s); (_i) <= (_e); (_i) += 1)
#define rfor(_i, _n) for((_i)=(_n)-1; ((_i) >= 0); (_i) -= 1)
#define rfore(_i, _n) for((_i)=(_n); (_i) >= 0; (_i) -= 1)
#define rforre(_i, _b, _e) for ((_i) = (_b); (_i) >= (_e); (_i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#define foriter(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
#define blstr(b) (b ? "true" : "false")
#endif
using namespace std;
struct suc {
	int id;
	int cost;
	suc(const int i, const int c) {
		init(i, c);
	}
	void init(const int i, const int c) {
		id = i;
		cost = c;
	}
};
#define T 1000000000
#define N 5000
int n, m, t;
int p[N][N+1];
int s[N][N+1];
vector<suc> g[N];
vector<int> topa;
#define printd printf
bool read(void) {
	int i;
	int l, r, c;
	if (scanf("%d%d%d", &n, &m, &t) != 3)
		return false;
	forn(i, m) {
		scanf("%d%d%d", &l, &r, &c);
		--l, --r;
		g[l].push_back(suc(r, c));
	}
	return true;
}
void initpath(void) {
	int i, j;
	forn(i, N) forn(j, N+1) p[i][j] = -1;
}
void printpath(int i, int j) {
	if (i == -1) {
		printf("\n");
		return;
	}
	assert(j >= 1);
	printf("%d ", i+1);
	printpath(p[i][j], j-1);
}
void topsort(void) {
	int nin[N], i, left;
	stack<int> stk;
	vector<suc>::iterator it;
	forn(i, n) nin[i] = 0;
	forn(i, n) foriter(it, g[i]) ++nin[it->id];
	forn(i, n) if (nin[i] == 0) stk.push(i);
	while (!stk.empty()) {
		left = stk.top();
		stk.pop();
		topa.push_back(left);
		foriter(it, g[left]) if (--nin[it->id] == 0) stk.push(it->id);
	}
	assert((int)topa.size() == n);
}
inline void prints(int i, int j) {
	printf("dp: (%3d, %3d): %d\n", i+1, j, s[i][j]);
}
void solve(void) {
	const int thresh = T + 1;
	int left, rght, to;
	int cost, via;
	vector<suc>::iterator it;
	int i, j;
	topsort();
	initpath();
	rfor(i, n) {
		left = topa[i];
		s[left][1] = (left == n-1 ? 0 : thresh);
		forre(j, 2, n) {
			s[left][j] = thresh;
			to = -1;
			foriter(it, g[left]) {
				rght = it->id, cost = it->cost;
				via = cost + s[rght][j-1];
				if (via < s[left][j]) {
					s[left][j] = via;
					to = rght;
				}
			}
			p[left][j] = to;
		}
	}
	rforre(j, n, 1) if (s[0][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	printpath(0, j);
}
void clear(void) {
	int i;
	forn(i, N) g[i].clear();
	topa.clear();
	initpath();
}
int main(void) {
	while (read()) {
		solve();
	}
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define T 1000000001
#define N 5000
struct succer {
	int id;
	int cost;
	succer(int idx, int cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<int, N+1>, N> dp;
array<array<int, N+1>, N> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	printf("before topsort: n: %d\n", n);
	forn(i, n) foreach(it, nexts[i]) indg[it->id] = 0;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] += 1;
	forn(i, n) if (indg[i] == 0) stk.push(i);
	printf("after 3 forn: n: %d\n", n);
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	//assert(topi == n);
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right;
	int cost;
	veciter(succer) it;
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	printf("after topsort: n: %d\n", n);
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : T);
		forre(j, 2, n) {
			dp[i][j] = T;
			foreach(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] < T) {
					dp[i][j] = min(dp[i][j], it->cost + dp[k][j-1]);
					to = k;
				}
			}
			path[i][j] = to;
		}
	}
	printf("after dp: n: %d\n", n);
	i = 0;
	rforre(j, 4, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foriter(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define T 1000000001
#define N 5000
struct succer {
	int id;
	int cost;
	succer(int idx, int cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<int, N+1>, N> dp;
array<array<int, N+1>, N+1> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;

	forn(i, n) foriter(it, nexts[i]) indg[it->id] = 0;
	forn(i, n) foriter(it, nexts[i]) indg[it->id] += 1;
	forn(i, n) if (indg[i] == 0) stk.push(i);

	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foriter(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	assert(topi == n);
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right, cost;
	veciter(succer) it;
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : T);
		forre(j, 2, n) {
			dp[i][j] = T;
			foriter(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] < T) {
					dp[i][j] = min(dp[i][j], it->cost + dp[k][j-1]);
					to = k;
				}
			}
			path[i][j] = to;
		}
	}
	i = 0;
	rforre(j, n, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	while (i != n-1) {
		printf("%d ", i+1);
		i = path[i][j];
		--j;
	}
	printf("%d\n", n);
	return 0;
}


#include <array>
#include <cstdio>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define SWP(a, b) if ((a) != (b)) do {(a) ^= (b); (b) ^= (a); (a) ^= (b);} while(0)
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define printa(a, i, n) forn((i), (n)) cout << (a)[(i)] << tailer((i), (n-1))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
using namespace std;
#define N 5000
int n, m;
long long t;
array<vector<int>, N> appends;
array<int, N> to;
array<array<long long, N>, N> map;
int dfs(int start, long long remain)
{
	int maxv, nv;
	veciter(int) chl;
	if (remain < 0) return INT_MIN;
	if (start == n-1) return 1;
	maxv = INT_MIN;
	for (chl = appends[start].begin(); chl != appends[start].end(); ++chl) {
		nv = dfs(*chl, remain-map[start][*chl]);
		if (maxv < nv) {
			maxv = nv;
			to[start] = *chl;
		}
	}
	if (maxv == INT_MIN) return maxv;
	return maxv + 1;
}
void printpath(int start)
{
	if (start == -1) return;
	printf("%d ", start+1);
	printpath(to[start]);
}
int main(void)
{
	int i;
	int left, right, ans;
	long long cost;
        scanf("%d%d%lld", &n, &m, &t);
        forn(i, m) {
                scanf("%d%d%lld", &left, &right, &cost);
		--left, --right;
                map[left][right] = cost;
		appends[left].push_back(right);
        }
	to.fill(-1);
	ans = dfs(0, t);
	printf("%d\n", ans);
	printpath(0);
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define T 1000000001
#define N 5000
struct succer {
	int id;
	int cost;
	succer(int idx, int cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<int, N+1>, N> dp;
array<array<int, N+1>, N> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] = 0;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] += 1;
	forn(i, n) if (indg[i] == 0) stk.push(i);
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	while (1);
	assert(topi == n);
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right;
	int cost;
	veciter(succer) it;
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	printf("after topsort: n: %d\n", n);
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : T);
		forre(j, 2, n) {
			dp[i][j] = T;
			foreach(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] < T) {
					dp[i][j] = min(dp[i][j], it->cost + dp[k][j-1]);
					to = k;
				}
			}
			path[i][j] = to;
		}
	}
	printf("after dp: n: %d\n", n);
	i = 0;
	rforre(j, 4, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <map>
#include <stack>
#include <string>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <algorithm>
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define max3(a, b, c) std::max(std::max((a),(b)), (c))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(_i, _n) for ((_i) = 0; (_i) < (_n); (_i) += 1)
#define fore(_i, _n) for ((_i) = 0; (_i) <= (_n); (_i) += 1)
#define forr(_i, _s, _e) for((_i) = (_s); (_i) < (_e); (_i) += 1)
#define forre(_i, _s, _e) for((_i) = (_s); (_i) <= (_e); (_i) += 1)
#define rfor(_i, _n) for((_i)=(_n)-1; ((_i) >= 0); (_i) -= 1)
#define rfore(_i, _n) for((_i)=(_n); (_i) >= 0; (_i) -= 1)
#define rforre(_i, _b, _e) for ((_i) = (_b); (_i) >= (_e); (_i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#define foriter(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
#endif
using namespace std;
#define N 5000
const int large = 1000000001;
int n, m, t;
vector<vector<int>> graph(N);
vector<int> top;
int s[N][N+1], x[N][N+1], costs[N][N];
void topsort(void) {
	int i, inds[N];
	stack<int> stk;
	vector<int>::iterator nxt;
	vector<int> *nxts;
	forn(i, n) inds[i] = 0;
	forn(i, n) {
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) ++inds[*nxt];
	}
	forn(i, n) if (inds[i] == 0) stk.push(i);
	while (!stk.empty()) {
		i = stk.top();
		stk.pop();
		top.push_back(i);
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) {
			--inds[*nxt];
			if (inds[*nxt] == 0) stk.push(*nxt);
		}
	}
}
bool read(void) {
	int i, j, left, rght, cost;
	forn(i, n) fore(j, m) x[i][j] = -1;
	forn(i, N) graph[i].clear();
	top.clear();
	if (scanf("%d%d%d", &n, &m, &t) != 3)
		return false;
	forn(i, m) {
		scanf("%d%d%d", &left, &rght, &cost);
		--left, --rght;
		graph[left].push_back(rght);
		costs[left][rght] = cost;
	}
	return true;
}
void print_path(int i, int j) {
	if (i == -1 || j <= 0) {
		printf("\n");
		return;
	}
	printf("%d ", i+1);
	print_path(x[i][j], j-1);
}
void print_s(int i, int j) {
	printf("s[%2d][%2d]: %2d\n", i+1, j, s[i][j]);
}
void solve(void) {
	int i, j, u, c;
	vector<int>::iterator v;
	vector<int> *nxts;
	s[n-1][1] = 0;
	forre(j, 2, m) s[n-1][j] = large;
	topsort();
	rfor(i, n) {
		u = top[i];
		if (u == n-1) continue;
		s[u][1] = large;
		forre(j, 2, m) {
			s[u][j] = large;
			nxts = &graph[u];
			for (v = nxts->begin(); v != nxts->end(); ++v) {
				c = costs[u][*v]+s[*v][j-1];
				if (s[u][j] > c) s[u][j] = c, x[u][j] = *v;
			}
		}
	}
	rforre(j, m, 1) {
		if (s[0][j] <= t) break;
	}
	printf("%d\n", j);
	if (j >= 0) print_path(0, j);
}
int main(void) {
	while (read()) solve();
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define T 1000000001
#define N 5000
struct succer {
	int id;
	int cost;
	succer(int idx, int cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<int, N+1>, N> dp;
array<array<int, N+1>, N> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] = 0;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] += 1;
	forn(i, n) if (indg[i] == 0) stk.push(i);
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	assert(topi == n);
	forn(i, n) printf("%d%s", top[i], tailer(i, n-1));
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right;
	int cost;
	veciter(succer) it;
	freopen("Inputs/721C", "r", stdin);
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	//while (1);
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : T);
		forre(j, 2, n) {
			dp[i][j] = T;
			foreach(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] < T) {
					dp[i][j] = min(dp[i][j], it->cost + dp[k][j-1]);
					to = k;
				}
			}
			path[i][j] = to;
		}
	}
	//while (1);
	i = 0;
	for (j = 4; j >= 1; --j)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	while (1);
	while (i != n-1) {
		printf("%d ", i+1);
		i = path[i][j];
		--j;
	}
	printf("%d\n", n);
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define T 1000000001
#define N 5000
struct succer {
	int id;
	int cost;
	succer(int idx, int cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<int, N+1>, N> dp;
array<array<int, N+1>, N> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	printf("before topsort: n: %d\n", n);
	forn(i, n) indg[i] = 0;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] += 1;
	forn(i, n) printf("%d%s", indg[i], tailer(i, n-1));
	forn(i, n) if (indg[i] == 0) stk.push(i);
	printf("after 3 forn: n: %d\n", n);
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	printf("topi: %d\n", topi);
	//assert(topi == n);
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right;
	int cost;
	veciter(succer) it;
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	printf("after topsort: n: %d\n", n);
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : T);
		forre(j, 2, n) {
			dp[i][j] = T;
			foreach(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] < T) {
					dp[i][j] = min(dp[i][j], it->cost + dp[k][j-1]);
					to = k;
				}
			}
			path[i][j] = to;
		}
	}
	printf("after dp: n: %d\n", n);
	i = 0;
	rforre(j, 4, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define T 1000000001
#define N 5000
struct succer {
	int id;
	int cost;
	succer(int idx, int cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<int, N+1>, N> dp;
array<array<int, N+1>, N> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] = 0;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] += 1;
	forn(i, n) if (indg[i] == 0) stk.push(i);
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	assert(topi == n);
	forn(i, n) printf("%d%s", top[i], tailer(i, n-1));
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right;
	int cost;
	veciter(succer) it;
	freopen("Inputs/721C", "r", stdin);
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : T);
		forre(j, 2, n) {
			dp[i][j] = T;
			foreach(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] < T) {
					dp[i][j] = min(dp[i][j], it->cost + dp[k][j-1]);
					to = k;
				}
			}
			path[i][j] = to;
		}
	}
	i = 0;
	rforre(j, n, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	while (1);
	while (i != n-1) {
		printf("%d ", i+1);
		i = path[i][j];
		--j;
	}
	printf("%d\n", n);
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <map>
#include <stack>
#include <string>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <algorithm>
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define max3(a, b, c) std::max(std::max((a),(b)), (c))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(_i, _n) for ((_i) = 0; (_i) < (_n); (_i) += 1)
#define fore(_i, _n) for ((_i) = 0; (_i) <= (_n); (_i) += 1)
#define forr(_i, _s, _e) for((_i) = (_s); (_i) < (_e); (_i) += 1)
#define forre(_i, _s, _e) for((_i) = (_s); (_i) <= (_e); (_i) += 1)
#define rfor(_i, _n) for((_i)=(_n)-1; ((_i) >= 0); (_i) -= 1)
#define rfore(_i, _n) for((_i)=(_n); (_i) >= 0; (_i) -= 1)
#define rforre(_i, _b, _e) for ((_i) = (_b); (_i) >= (_e); (_i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#define foriter(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
#endif
using namespace std;
#define N 5000
#define foreachp(_i, _p, _c) for (_p = &(_c), _i = _p->begin(); _i != _p->end(); ++_i)
const int large = 1000000001;
struct append {
	int id, cost;
	append(int i, int c) {
		id = i;
		cost = c;
	}
};
int n, m, t;
vector<vector<append>> graph(N);
vector<int> top;
int s[N][N+1], x[N][N+1];
void topsort(void) {
	int i, inds[N];
	stack<int> stk;
	vector<append>::iterator nxt;
	vector<append> *nxts;
	forn(i, n) inds[i] = 0;
	forn(i, n) {
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) ++inds[nxt->id];
	}
	forn(i, n) if (inds[i] == 0) stk.push(i);
	while (!stk.empty()) {
		i = stk.top();
		stk.pop();
		top.push_back(i);
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) {
			--inds[nxt->id];
			if (inds[nxt->id] == 0) stk.push(nxt->id);
		}
	}
	assert((int)top.size() == n);
}
bool read(void) {
	int i, j, left, rght, cost;
	forn(i, n) fore(j, m) x[i][j] = -1;
	forn(i, N) graph[i].clear();
	top.clear();
	if (scanf("%d%d%d", &n, &m, &t) != 3)
		return false;
	forn(i, m) {
		scanf("%d%d%d", &left, &rght, &cost);
		--left, --rght;
		graph[left].push_back(append(rght, cost));
	}
	return true;
}
void print_path(int i, int j) {
	if (i == -1 || j <= 0) {
		printf("\n");
		return;
	}
	printf("%d ", i+1);
	print_path(x[i][j], j-1);
}
inline void print_s(int i, int j) {
	//printf("s[%2d][%2d]: %d\n", i+1, j, s[i][j]);
}
void solve(void) {
	int i, j, u, c;
	vector<append>::iterator v;
	vector<append> *nxts;
	s[n-1][1] = 0;
	forre(j, 2, m) s[n-1][j] = large;
	forre(j, 1, m) print_s(n-1, j);
	topsort();
	rfor(i, n) {
		u = top[i];
		if (u == n-1) continue;
		s[u][1] = large;
		print_s(u, 1);
		forre(j, 2, m) {
			s[u][j] = large;
			nxts = &graph[u];
			for (v = nxts->begin(); v != nxts->end(); ++v) {
				c = v->cost + s[v->id][j-1];
				if (s[u][j] > c) s[u][j] = c, x[u][j] = v->id;
			}
			print_s(u, j);
		}
	}
	rforre(j, m, 1) {
		if (n == 1000 && m == 999) {
			vector<int> debug;
			forr(i, 0, 10) printf("%d%s", top[i], tailer(i, 9));
			printf("%d -> %d: cost: %d\n", 0, graph[0][0].id, graph[0][0].cost);
			forre(j, 1, m) if (s[982][j] <= t) debug.push_back(j);
			printf("%d, %d: %d\n", 982, debug[0], s[982][debug[0]]);
		}
		print_s(0, j);
		if (s[0][j] <= t) break;
	}
	printf("%d\n", j);
	if (j >= 0) print_path(0, j);
}
int main(void) {

	while (read()) solve();
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <map>
#include <stack>
#include <string>
#include <vector>
#ifndef __INCLUDE_COMMON_H
#define __INCLUDE_COMMON_H
#include <algorithm>
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define max3(a, b, c) std::max(std::max((a),(b)), (c))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(_i, _n) for ((_i) = 0; (_i) < (_n); (_i) += 1)
#define fore(_i, _n) for ((_i) = 0; (_i) <= (_n); (_i) += 1)
#define forr(_i, _s, _e) for((_i) = (_s); (_i) < (_e); (_i) += 1)
#define forre(_i, _s, _e) for((_i) = (_s); (_i) <= (_e); (_i) += 1)
#define rfor(_i, _n) for((_i)=(_n)-1; ((_i) >= 0); (_i) -= 1)
#define rfore(_i, _n) for((_i)=(_n); (_i) >= 0; (_i) -= 1)
#define rforre(_i, _b, _e) for ((_i) = (_b); (_i) >= (_e); (_i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#define foriter(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
#define blstr(b) (b ? "true" : "false")
#endif
using namespace std;
struct suc {
	int id;
	int cost;
	suc(const int i, const int c) {
		init(i, c);
	}
	void init(const int i, const int c) {
		id = i;
		cost = c;
	}
};
#define T 1000000000
#define N 5000
int n, m, t;
int p[N][N+1];
int s[N][N+1];
vector<suc> g[N];
vector<int> topa;
#define printd printf
bool read(void) {
	int i;
	int l, r, c;
	if (scanf("%d%d%d", &n, &m, &t) != 3)
		return false;
	forn(i, m) {
		scanf("%d%d%d", &l, &r, &c);
		--l, --r;
		g[l].push_back(suc(r, c));
	}
	return true;
}
void initpath(void) {
	int i, j;
	forn(i, N) forn(j, N+1) p[i][j] = -1;
}
void printpath(int i, int j) {
	if (i == -1) {
		printf("\n");
		return;
	}
	assert(j >= 1);
	printf("%d ", i+1);
	printpath(p[i][j], j-1);
}
void topsort(void) {
	int nin[N], i, left;
	stack<int> stk;
	vector<suc>::iterator it;
	forn(i, n) nin[i] = 0;
	forn(i, n) foriter(it, g[i]) ++nin[it->id];
	forn(i, n) if (nin[i] == 0) stk.push(i);
	while (!stk.empty()) {
		left = stk.top();
		stk.pop();
		topa.push_back(left);
		foriter(it, g[left]) if (--nin[it->id] == 0) stk.push(it->id);
	}
	assert((int)topa.size() == n);
}
inline void prints(int i, int j) {
	printf("dp: (%3d, %3d): %d\n", i+1, j, s[i][j]);
}
void solve(void) {
	const int thresh = T + 1;
	int left, rght, to;
	int cost, via;
	vector<suc>::iterator it;
	int i, j;
	topsort();
	initpath();
	rfor(i, n) {
		left = topa[i];
		s[left][1] = (left == n-1 ? 0 : thresh);
		forre(j, 2, m) {
			s[left][j] = thresh;
			to = -1;
			foriter(it, g[left]) {
				rght = it->id, cost = it->cost;
				via = cost + s[rght][j-1];
				if (via < s[left][j]) {
					s[left][j] = via;
					to = rght;
				}
			}
			p[left][j] = to;
		}
	}
	rforre(j, m, 1) if (s[0][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	printpath(0, j);
}
void clear(void) {
	int i;
	forn(i, N) g[i].clear();
	topa.clear();
	initpath();
}
int main(void) {
	while (read()) {
		solve();
	}
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define N 5000
struct succer {
	int id;
	long long cost;
	succer(int idx, long long cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<long long, N+1>, N> dp, path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	forn(i, n)
		foreach(it, nexts[i])
			indg[it->id] = 0;
	forn(i, n) {
		foreach(it, nexts[i]) {
			indg[it->id] += 1;
		}
	}
	forn(i, n) {
		if (indg[i] == 0)
			stk.push(i);
	}
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	assert(topi == n);
}
void dpfill(int i, int j)
{
	veciter(succer) it;
	long long mincost, cost;
	int to;
	if (i == n-1 and j == 1) return;
	mincost = LLONG_MAX;
	foreach(it, nexts[i]) {
		cost = it->cost + access(dp[it->id], j-1, j, LLONG_MAX);
		LLOF(cost);
		if (cost < mincost) {
			mincost = cost;
			to = it->id;
		}
	}
	dp[i][j] = mincost;
	path[i][j] = to;
}
void printpath(int i, int j)
{
	int next;
	printf("%d ", i+1);
	if (i == n-1) return;
	next = path[i][j];
	printpath(next, j-1);
}
int main(void)
{
	int i, j;
	int left, right, cost;
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	forn(i, n) fore(j, n) dp[i][j] = INT_MAX;
	dp[n-1][1] = 0;
	for(--i; i >= 0; --i)
		fore(j, n)
			dpfill(top[i], j);
	i = 0;
	rforre(j, n, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	printpath(0, j);
	puts("");
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <map>
#include <stack>
#include <string>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <algorithm>
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define max3(a, b, c) std::max(std::max((a),(b)), (c))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(_i, _n) for ((_i) = 0; (_i) < (_n); (_i) += 1)
#define fore(_i, _n) for ((_i) = 0; (_i) <= (_n); (_i) += 1)
#define forr(_i, _s, _e) for((_i) = (_s); (_i) < (_e); (_i) += 1)
#define forre(_i, _s, _e) for((_i) = (_s); (_i) <= (_e); (_i) += 1)
#define rfor(_i, _n) for((_i)=(_n)-1; ((_i) >= 0); (_i) -= 1)
#define rfore(_i, _n) for((_i)=(_n); (_i) >= 0; (_i) -= 1)
#define rforre(_i, _b, _e) for ((_i) = (_b); (_i) >= (_e); (_i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#define foriter(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
#endif
using namespace std;
#define N 5000
#define foreachp(_i, _p, _c) for (_p = &(_c), _i = _p->begin(); _i != _p->end(); ++_i)
const int large = 1000000001;
struct append {
	int id, cost;
	append(int i, int c) {
		id = i;
		cost = c;
	}
};
int n, m, t;
vector<vector<append>> graph(N);
vector<int> top;
int s[N][N+1], x[N][N+1];
void topsort(void) {
	int i, inds[N];
	stack<int> stk;
	vector<append>::iterator nxt;
	vector<append> *nxts;
	forn(i, n) inds[i] = 0;
	forn(i, n) {
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) ++inds[nxt->id];
	}
	forn(i, n) if (inds[i] == 0) stk.push(i);
	while (!stk.empty()) {
		i = stk.top();
		stk.pop();
		top.push_back(i);
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) {
			--inds[nxt->id];
			if (inds[nxt->id] == 0) stk.push(nxt->id);
		}
	}
	assert((int)top.size() == n);
}
bool read(void) {
	int i, j, left, rght, cost;
	forn(i, n) fore(j, n) x[i][j] = -1;
	forn(i, N) graph[i].clear();
	top.clear();
	if (scanf("%d%d%d", &n, &m, &t) != 3)
		return false;
	forn(i, m) {
		scanf("%d%d%d", &left, &rght, &cost);
		--left, --rght;
		graph[left].push_back(append(rght, cost));
	}
	return true;
}
void print_path(int i, int j) {
	if (i == -1 || j <= 0) {
		printf("\n");
		return;
	}
	printf("%d ", i+1);
	print_path(x[i][j], j-1);
}
inline void print_s(int i, int j) {
	//printf("s[%2d][%2d]: %d\n", i+1, j, s[i][j]);
}
void solve(void) {
	int i, j, u, c;
	vector<append>::iterator v;
	vector<append> *nxts;
	s[n-1][1] = 0;
	forre(j, 2, n) s[n-1][j] = large;
	forre(j, 1, n) print_s(n-1, j);
	topsort();
	rfor(i, n) {
		u = top[i];
		if (u == n-1) continue;
		s[u][1] = large;
		print_s(u, 1);
		forre(j, 2, n) {
			s[u][j] = large;
			nxts = &graph[u];
			for (v = nxts->begin(); v != nxts->end(); ++v) {
				c = v->cost + s[v->id][j-1];
				if (s[u][j] > c) s[u][j] = c, x[u][j] = v->id;
			}
			print_s(u, j);
		}
	}
	rforre(j, n, 1) {
		print_s(0, j);
		if (s[0][j] <= t) break;
	}
	printf("%d\n", j);
	if (j >= 0) print_path(0, j);
}
int main(void) {
	while (read()) solve();
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define T 1000000001
#define N 5000
struct succer {
	int id;
	int cost;
	succer(int idx, int cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<int, N+1>, N> dp;
array<array<int, N+1>, N> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] = 0;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] += 1;
	forn(i, n) if (indg[i] == 0) stk.push(i);
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	assert(topi == n);
	//forn(i, n) printf("%d%s", top[i], tailer(i, n-1));
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right;
	int cost;
	veciter(succer) it;
	freopen("Inputs/721C", "r", stdin);
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	//while (1);
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : T);
		forre(j, 2, n) {
			dp[i][j] = T;
			foreach(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] < T) {
					dp[i][j] = min(dp[i][j], it->cost + dp[k][j-1]);
					to = k;
				}
			}
			path[i][j] = to;
		}
	}
	//while (1);
	i = 0;
	printf("n: %d\n", n);
	for (j = 4; j >= 1; --j)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <map>
#include <stack>
#include <string>
#include <vector>
#ifndef __INCLUDE_COMMON_H
#define __INCLUDE_COMMON_H
#include <algorithm>
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define max3(a, b, c) std::max(std::max((a),(b)), (c))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(_i, _n) for ((_i) = 0; (_i) < (_n); (_i) += 1)
#define fore(_i, _n) for ((_i) = 0; (_i) <= (_n); (_i) += 1)
#define forr(_i, _s, _e) for((_i) = (_s); (_i) < (_e); (_i) += 1)
#define forre(_i, _s, _e) for((_i) = (_s); (_i) <= (_e); (_i) += 1)
#define rfor(_i, _n) for((_i)=(_n)-1; ((_i) >= 0); (_i) -= 1)
#define rfore(_i, _n) for((_i)=(_n); (_i) >= 0; (_i) -= 1)
#define rforre(_i, _b, _e) for ((_i) = (_b); (_i) >= (_e); (_i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#define foriter(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
#define blstr(b) (b ? "true" : "false")
bool scanfnint(int *a, const int n) {
	for (int i = 0; i < n; ++i)
		if (scanf("%d", &a[i]) != 1)
			return false;
	return true;
}
void printnint(const int *a, const int n, const char *tag="") {
	printf("%s", tag);
	for (int i = 0; i < n; ++i)
		printf("%5d%s", a[i], i == n-1 ? "\n" : " ");
}
#endif
using namespace std;
#define N 5000
const int huge = 1000000001;
struct suc {
	int id, cost;
	suc(int i, int c) {
		id = i;
		cost = c;
	}
};
int n, m, t;
vector<suc> g[N];
int to[N][N+1], s[N][N+1];
bool read(void) {
	int i, left, rght, cost;
	if (scanf("%d%d%d", &n, &m, &t) != 3)
		return false;
	forn(i, m) {
		scanf("%d%d%d", &left, &rght, &cost);
		--left, --rght;
		g[left].push_back(suc(rght, cost));
	}
	return true;
}
int topord[N];
void topsort(void) {
	stack<int> topstk;
	int nin[N];
	int i, topi;
	vector<suc>::iterator it;
	forn(i, n) nin[i] = 0;
	forn(i, n) foriter(it, g[i]) ++nin[it->id];
	forn(i, n) if (nin[i] == 0) topstk.push(i);
	topi = 0;
	while (!topstk.empty()) {
		i = topstk.top();
		topstk.pop();
		topord[topi++] = i;
		foriter(it, g[i]) {
			--nin[it->id];
			if (nin[it->id] == 0)
				topstk.push(it->id);
		}
	}
}
void printpath(int i, int j) {
	if (i == -1) {
		printf("\n");
		return;
	}
	printf("%d ", i+1);
	printpath(to[i][j], j-1);
}
void prints(int i, int j) {
	printf("[%2d][%2d]: %d\n", i+1, j, s[i][j]);
}
void solve(void) {
	int left, rght, cost, use;
	int i, j;
	vector<suc>::iterator it;
	topsort();
	rfor(i, n) {
		left = topord[i];
		s[left][1] = (left == n-1 ? 0 : huge);
		to[left][1] = -1;
		forre(j, 2, n) {
			s[left][j] = huge;
			to[left][j] = -1;
			foriter(it, g[left]) {
				rght = it->id;
				cost = it->cost;
				use = s[rght][j-1] + cost;
				if (use < s[left][j]) {
					s[left][j] = use;
					to[left][j] = rght;
				}
			}
		}
	}
	rforre(j, n, 1) if (s[0][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	printpath(0, j);
}
void clear(void) {
	int i;
	forn(i, N) g[i].clear();
}
int main(void) {
	while (read()) {
		solve();
	}
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <map>
#include <stack>
#include <string>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <algorithm>
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define max3(a, b, c) std::max(std::max((a),(b)), (c))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(_i, _n) for ((_i) = 0; (_i) < (_n); (_i) += 1)
#define fore(_i, _n) for ((_i) = 0; (_i) <= (_n); (_i) += 1)
#define forr(_i, _s, _e) for((_i) = (_s); (_i) < (_e); (_i) += 1)
#define forre(_i, _s, _e) for((_i) = (_s); (_i) <= (_e); (_i) += 1)
#define rfor(_i, _n) for((_i)=(_n)-1; ((_i) >= 0); (_i) -= 1)
#define rfore(_i, _n) for((_i)=(_n); (_i) >= 0; (_i) -= 1)
#define rforre(_i, _b, _e) for ((_i) = (_b); (_i) >= (_e); (_i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#define foriter(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
#endif
using namespace std;
#define N 5000
#define foreachp(_i, _p, _c) for (_p = &(_c), _i = _p->begin(); _i != _p->end(); ++_i)
const int large = 1000000001;
struct append {
	int id, cost;
	append(int i, int c) {
		id = i;
		cost = c;
	}
};
int n, m, t;
vector<vector<append>> graph(N);
vector<int> top;
int s[N][N+1], x[N][N+1];
void topsort(void) {
	int i, inds[N];
	stack<int> stk;
	vector<append>::iterator nxt;
	vector<append> *nxts;
	forn(i, n) inds[i] = 0;
	forn(i, n) {
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) ++inds[nxt->id];
	}
	forn(i, n) if (inds[i] == 0) stk.push(i);
	while (!stk.empty()) {
		i = stk.top();
		stk.pop();
		top.push_back(i);
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) {
			--inds[nxt->id];
			if (inds[nxt->id] == 0) stk.push(nxt->id);
		}
	}
	assert((int)top.size() == n);
}
bool read(void) {
	int i, j, left, rght, cost;
	forn(i, n) fore(j, m) x[i][j] = -1;
	forn(i, N) graph[i].clear();
	top.clear();
	if (scanf("%d%d%d", &n, &m, &t) != 3)
		return false;
	forn(i, m) {
		scanf("%d%d%d", &left, &rght, &cost);
		--left, --rght;
		graph[left].push_back(append(rght, cost));
	}
	return true;
}
void print_path(int i, int j) {
	if (i == -1 || j <= 0) {
		printf("\n");
		return;
	}
	printf("%d ", i+1);
	print_path(x[i][j], j-1);
}
inline void print_s(int i, int j) {
	//printf("s[%2d][%2d]: %d\n", i+1, j, s[i][j]);
}
void solve(void) {
	int i, j, u, c;
	vector<append>::iterator v;
	vector<append> *nxts;
	s[n-1][1] = 0;
	forre(j, 2, m) s[n-1][j] = large;
	forre(j, 1, m) print_s(n-1, j);
	topsort();
	rfor(i, n) {
		u = top[i];
		if (u == n-1) continue;
		s[u][1] = large;
		print_s(u, 1);
		forre(j, 2, m) {
			s[u][j] = large;
			nxts = &graph[u];
			for (v = nxts->begin(); v != nxts->end(); ++v) {
				c = v->cost + s[v->id][j-1];
				if (s[u][j] > c) s[u][j] = c, x[u][j] = v->id;
			}
			print_s(u, j);
		}
	}
	rforre(j, m, 1) {
		if (n == 1000 && m == 999) {
			vector<int> debug;
			forn(i, n) forre(j, 1, m) if (s[i][j] <= t) debug.push_back(j);
			sort(debug.begin(), debug.end());
			forr(i, 950, n) printf("%d%s\n", debug[i], tailer(i, n-1));
		}
		print_s(0, j);
		if (s[0][j] <= t) break;
	}
	printf("%d\n", j);
	if (j >= 0) print_path(0, j);
}
int main(void) {

	while (read()) solve();
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define T 1000000001
#define N 5000
struct succer {
	int id;
	int cost;
	succer(int idx, int cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<int, N+1>, N> dp;
array<array<int, N+1>, N> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	forn(i, n) indg[i] = 0;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] += 1;
	forn(i, n) if (indg[i] == 0) stk.push(i);
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	assert(topi == n);
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right;
	int cost;
	veciter(succer) it;
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : T);
		forre(j, 2, n) {
			dp[i][j] = T;
			foreach(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] < T) {
					dp[i][j] = min(dp[i][j], it->cost + dp[k][j-1]);
					to = k;
				}
			}
			path[i][j] = to;
		}
	}
	i = 0;
	rforre(j, n, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	while (i != n-1) {
		printf("%d ", i+1);
		i = path[i][j];
		--j;
	}
	printf("%d\n", n);
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <map>
#include <stack>
#include <string>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <algorithm>
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define max3(a, b, c) std::max(std::max((a),(b)), (c))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(_i, _n) for ((_i) = 0; (_i) < (_n); (_i) += 1)
#define fore(_i, _n) for ((_i) = 0; (_i) <= (_n); (_i) += 1)
#define forr(_i, _s, _e) for((_i) = (_s); (_i) < (_e); (_i) += 1)
#define forre(_i, _s, _e) for((_i) = (_s); (_i) <= (_e); (_i) += 1)
#define rfor(_i, _n) for((_i)=(_n)-1; ((_i) >= 0); (_i) -= 1)
#define rfore(_i, _n) for((_i)=(_n); (_i) >= 0; (_i) -= 1)
#define rforre(_i, _b, _e) for ((_i) = (_b); (_i) >= (_e); (_i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#define foriter(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
#endif
using namespace std;
#define N 5000
#define foreachp(_i, _p, _c) for (_p = &(_c), _i = _p->begin(); _i != _p->end(); ++_i)
const int large = 1000000001;
struct append {
	int id, cost;
	append(int i, int c) {
		id = i;
		cost = c;
	}
};
int n, m, t;
vector<vector<append>> graph(N);
vector<int> top;
int s[N][N+1], x[N][N+1];
void topsort(void) {
	int i, inds[N];
	stack<int> stk;
	vector<append>::iterator nxt;
	vector<append> *nxts;
	forn(i, n) inds[i] = 0;
	forn(i, n) {
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) ++inds[nxt->id];
	}
	forn(i, n) if (inds[i] == 0) stk.push(i);
	while (!stk.empty()) {
		i = stk.top();
		stk.pop();
		top.push_back(i);
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) {
			--inds[nxt->id];
			if (inds[nxt->id] == 0) stk.push(nxt->id);
		}
	}
	assert((int)top.size() == n);
}
bool read(void) {
	int i, j, left, rght, cost;
	forn(i, n) fore(j, m) x[i][j] = -1;
	forn(i, N) graph[i].clear();
	top.clear();
	if (scanf("%d%d%d", &n, &m, &t) != 3)
		return false;
	forn(i, m) {
		scanf("%d%d%d", &left, &rght, &cost);
		--left, --rght;
		graph[left].push_back(append(rght, cost));
	}
	return true;
}
void print_path(int i, int j) {
	if (i == -1 || j <= 0) {
		printf("\n");
		return;
	}
	printf("%d ", i+1);
	print_path(x[i][j], j-1);
}
inline void print_s(int i, int j) {
	//printf("s[%2d][%2d]: %d\n", i+1, j, s[i][j]);
}
void solve(void) {
	int i, j, u, c;
	vector<append>::iterator v;
	vector<append> *nxts;
	s[n-1][1] = 0;
	forre(j, 2, m) s[n-1][j] = large;
	forre(j, 1, m) print_s(n-1, j);
	topsort();
	rfor(i, n) {
		u = top[i];
		if (u == n-1) continue;
		s[u][1] = large;
		print_s(u, 1);
		forre(j, 2, m) {
			s[u][j] = large;
			nxts = &graph[u];
			for (v = nxts->begin(); v != nxts->end(); ++v) {
				c = v->cost + s[v->id][j-1];
				if (s[u][j] > c) s[u][j] = c, x[u][j] = v->id;
			}
			print_s(u, j);
		}
	}
	rforre(j, m, 1) {
		if (n == 1000 && m == 999) {
			vector<int> debug;
			forn(i, n) forre(j, 1, m) if (s[i][j] <= t) debug.push_back(j);
			sort(debug.begin(), debug.end());
			forn(i, n) printf("%d%s\n", debug[i], tailer(i, n-1));
		}
		print_s(0, j);
		if (s[0][j] <= t) break;
	}
	printf("%d\n", j);
	if (j >= 0) print_path(0, j);
}
int main(void) {
	while (read()) solve();
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define T 1000000001
#define N 5000
struct succer {
	int id;
	int cost;
	succer(int idx, int cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<int, N+1>, N> dp;
array<array<int, N+1>, N> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] = 0;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] += 1;
	forn(i, n) if (indg[i] == 0) stk.push(i);
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	assert(topi == n);
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right;
	int cost;
	veciter(succer) it;
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	printf("after topsort: n: %d\n", n);
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : T);
		forre(j, 2, n) {
			dp[i][j] = T;
			foreach(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] < T) {
					dp[i][j] = min(dp[i][j], it->cost + dp[k][j-1]);
					to = k;
				}
			}
			path[i][j] = to;
		}
	}
	printf("after dp: n: %d\n", n);
	i = 0;
	rforre(j, 4, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	while (i != n-1) {
		printf("%d ", i+1);
		i = path[i][j];
		--j;
	}
	printf("%d\n", n);
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define T 1000000001
#define N 5000
struct succer {
	int id;
	int cost;
	succer(int idx, int cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<int, N+1>, N> dp;
array<array<int, N+1>, N+1> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	forn(i, n)
		foreach(it, nexts[i])
			indg[it->id] = 0;
	forn(i, n) {
		foreach(it, nexts[i]) {
			indg[it->id] += 1;
		}
	}
	forn(i, n) {
		if (indg[i] == 0)
			stk.push(i);
	}
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	assert(topi == n);
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right;
	int cost;
	veciter(succer) it;
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : T);
		forre(j, 2, n) {
			dp[i][j] = T;
			foreach(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] < T) {
					dp[i][j] = min(dp[i][j], it->cost + dp[k][j-1]);
					to = k;
				}
			}
			path[i][j] = to;
		}
	}
	i = 0;
	rforre(j, n, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	while (i != n-1) {
		printf("%d ", i+1);
		i = path[i][j];
		--j;
	}
	printf("%d\n", n);
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define N 5000
struct succer {
	int id;
	long long cost;
	succer(int idx, long long cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<long long, N+1>, N> dp;
array<int, N+1> path;
array<long long, N+1> best;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	forn(i, n)
		foreach(it, nexts[i])
			indg[it->id] = 0;
	forn(i, n) {
		foreach(it, nexts[i]) {
			indg[it->id] += 1;
		}
	}
	forn(i, n) {
		if (indg[i] == 0)
			stk.push(i);
	}
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	assert(topi == n);
}
void dpfill(int i, int j)
{
	veciter(succer) it;
	long long mincost, cost;
	int to;
	if (i == n-1 and j == 1) return;
	mincost = LLONG_MAX;
	foreach(it, nexts[i]) {
		cost = it->cost + access(dp[it->id], j-1, j, LLONG_MAX);
		LLOF(cost);
		if (cost < mincost) {
			mincost = cost;
			to = it->id;
		}
	}
	dp[i][j] = mincost;
	if (mincost < best[i]) {
		best[i] = mincost;
		path[i] = to;
	}
}
void printpath(int i)
{
	printf("%d ", i+1);
	if (i == n-1) return;
	printpath(path[i]);
}
void pathinit(void)
{
	vecsize(long long) i;
	forn(i, best.size()) best[i] = LLONG_MAX;
}
int main(void)
{
	int i, j;
	int left, right, cost;
	pathinit();
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	forn(i, n) fore(j, n) dp[i][j] = INT_MAX;
	dp[n-1][1] = 0;
	for(--i; i >= 0; --i)
		fore(j, n)
			dpfill(top[i], j);
	i = 0;
	rforre(j, n, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	printpath(0);
	puts("");
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define N 5000
struct succer {
	int id;
	long long cost;
	succer(int idx, long long cst) {
		id = idx;
		cost = cst;
	}
};
int n, m;
long long t;
array<array<long long, N+1>, N> dp;
array<array<int, N+1>, N+1> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	forn(i, n)
		foreach(it, nexts[i])
			indg[it->id] = 0;
	forn(i, n) {
		foreach(it, nexts[i]) {
			indg[it->id] += 1;
		}
	}
	forn(i, n) {
		if (indg[i] == 0)
			stk.push(i);
	}
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	assert(topi == n);
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right;
	long long cost;
	veciter(succer) it;
	scanf("%d%d%lld", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%lld", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : LLONG_MAX);
		forre(j, 2, n) {
			dp[i][j] = LLONG_MAX;
			foreach(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] != LLONG_MAX) {
					dp[i][j] = min(dp[i][j], it->cost + dp[k][j-1]);
					to = k;
				}
			}
			path[i][j] = to;
		}
	}
	i = 0;
	rforre(j, n, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	while (i != n-1) {
		printf("%d ", i+1);
		i = path[i][j];
		--j;
	}
	printf("%d\n", n);
	return 0;
}


#include <array>
#include <cassert>
#include <cstdio>
#include <stack>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#define rforre(i, b, e) for ((i) = (b); (i) >= (e); (i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#endif
#define foreach(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
using namespace std;
#define T 1000000001
#define N 5000
struct succer {
	int id;
	int cost;
	succer(int idx, int cst) {
		id = idx;
		cost = cst;
	}
};
int n, m, t;
array<array<int, N+1>, N> dp;
array<array<int, N+1>, N> path;
array<vector<succer>, N> nexts;
array<int, N> top;
void topsort(void)
{
	array<int, N> indg;
	stack<int> stk;
	veciter(succer) it;
	int topi, i, next;
	forn(i, n) indg[i] = 0;
	forn(i, n) foreach(it, nexts[i]) indg[it->id] += 1;
	forn(i, n) if (indg[i] == 0) stk.push(i);
	topi = 0;
	while (not stk.empty()) {
		i = stk.top();
		stk.pop();
		top[topi++] = i;
		foreach(it, nexts[i]) {
			next = it->id;
			--indg[next];
			if (indg[next] == 0)
				stk.push(next);
		}
	}
	assert(topi == n);
}
int main(void)
{
	int i, j, k, ti, to;
	int left, right;
	int cost;
	veciter(succer) it;
	scanf("%d%d%d", &n, &m, &t);
	forn(i, m) {
		scanf("%d%d%d", &left, &right, &cost);
		--left, --right;
		nexts[left].push_back(succer(right, cost));
	}
	topsort();
	rforre(ti, n-1, 0) {
		i = top[ti];
		dp[i][1] = (i == n-1 ? 0 : T);
		forre(j, 2, n) {
			dp[i][j] = T;
			to = -1;
			foreach(it, nexts[i]) {
				k = it->id;
				if (dp[k][j-1] < T) {
					cost = it->cost + dp[k][j-1];
					if (dp[i][j] > cost) {
						dp[i][j] = cost;
						to = k;
					}
				}
			}
			path[i][j] = to;
		}
	}
	i = 0;
	rforre(j, n, 1)
		if (dp[i][j] <= t) break;
	assert(j >= 1);
	printf("%d\n", j);
	while (i != n-1) {
		printf("%d ", i+1);
		i = path[i][j];
		--j;
	}
	printf("%d\n", n);
	return 0;
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <map>
#include <stack>
#include <string>
#include <vector>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <algorithm>
#include <climits>
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define odd(x) ((x) & 1UL)
#define even(x) (!odd((x)))
#define sgn(n) (odd((n)) ? (-1) : (1))
#define max3(a, b, c) std::max(std::max((a),(b)), (c))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(_i, _n) for ((_i) = 0; (_i) < (_n); (_i) += 1)
#define fore(_i, _n) for ((_i) = 0; (_i) <= (_n); (_i) += 1)
#define forr(_i, _s, _e) for((_i) = (_s); (_i) < (_e); (_i) += 1)
#define forre(_i, _s, _e) for((_i) = (_s); (_i) <= (_e); (_i) += 1)
#define rfor(_i, _n) for((_i)=(_n)-1; ((_i) >= 0); (_i) -= 1)
#define rfore(_i, _n) for((_i)=(_n); (_i) >= 0; (_i) -= 1)
#define rforre(_i, _b, _e) for ((_i) = (_b); (_i) >= (_e); (_i) -= 1)
#define tailer(i, j) ((i) == (j) ? "\n" : " ")
#define access(_a, _i, _n, _obv) (ir((_i), 0, (_n)) ? (_a)[(_i)] : (_obv))
#define vecsize(t) vector<t>::size_type
#define veciter(t) vector<t>::iterator
#define foriter(_i, _c) for((_i) = (_c).begin(); (_i) != (_c).end(); ++(_i))
#endif
using namespace std;
#define N 5000
#define foreachp(_i, _p, _c) for (_p = &(_c), _i = _p->begin(); _i != _p->end(); ++_i)
const int large = 1000000001;
struct append {
	int id, cost;
	append(int i, int c) {
		id = i;
		cost = c;
	}
};
int n, m, t;
vector<vector<append>> graph(N);
vector<int> top;
int s[N][N+1], x[N][N+1];
void topsort(void) {
	int i, inds[N];
	stack<int> stk;
	vector<append>::iterator nxt;
	vector<append> *nxts;
	forn(i, n) inds[i] = 0;
	forn(i, n) {
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) ++inds[nxt->id];
	}
	forn(i, n) if (inds[i] == 0) stk.push(i);
	while (!stk.empty()) {
		i = stk.top();
		stk.pop();
		top.push_back(i);
		nxts = &graph[i];
		for (nxt = nxts->begin(); nxt != nxts->end(); ++nxt) {
			--inds[nxt->id];
			if (inds[nxt->id] == 0) stk.push(nxt->id);
		}
	}
	assert((int)top.size() == n);
}
bool read(void) {
	int i, j, left, rght, cost;
	forn(i, n) fore(j, m) x[i][j] = -1;
	forn(i, N) graph[i].clear();
	top.clear();
	if (scanf("%d%d%d", &n, &m, &t) != 3)
		return false;
	forn(i, m) {
		scanf("%d%d%d", &left, &rght, &cost);
		--left, --rght;
		graph[left].push_back(append(rght, cost));
	}
	return true;
}
void print_path(int i, int j) {
	if (i == -1 || j <= 0) {
		printf("\n");
		return;
	}
	printf("%d ", i+1);
	print_path(x[i][j], j-1);
}
inline void print_s(int i, int j) {
	//printf("s[%2d][%2d]: %d\n", i+1, j, s[i][j]);
}
void solve(void) {
	int i, j, u, c;
	vector<append>::iterator v;
	vector<append> *nxts;
	s[n-1][1] = 0;
	forre(j, 2, m) s[n-1][j] = large;
	forre(j, 1, m) print_s(n-1, j);
	topsort();
	rfor(i, n) {
		u = top[i];
		if (u == n-1) continue;
		s[u][1] = large;
		print_s(u, 1);
		forre(j, 2, m) {
			s[u][j] = large;
			nxts = &graph[u];
			for (v = nxts->begin(); v != nxts->end(); ++v) {
				c = v->cost + s[v->id][j-1];
				if (s[u][j] > c) s[u][j] = c, x[u][j] = v->id;
			}
			print_s(u, j);
		}
	}
	rforre(j, m, 1) {
		if (n == 1000 && m == 999) {
			vector<int> debug;
			forn(i, n) forre(j, 1, m) if (s[i][j] <= t) debug.push_back(j);
			sort(debug.begin(), debug.end());
			forr(i, 900, n) printf("%d%s\n", debug[i], tailer(i, n-1));
		}
		print_s(0, j);
		if (s[0][j] <= t) break;
	}
	printf("%d\n", j);
	if (j >= 0) print_path(0, j);
}
int main(void) {

	while (read()) solve();
	return 0;
}