#include <bits/stdc++.h>
#define NMAX 50005
using namespace std;
struct node
{
    int u ;
    int v ;
    int price;
    int id;
};

int n , m;
long long s;
int DSU[NMAX], sizeDSU[NMAX];
node graph[10*NMAX];
bool check[10*NMAX];
vector<int> location;
long long totalErase=0;

int find_root(int  u)
{
    return (DSU[u]==u)?u:DSU[u]=find_root(DSU[u]);
}

bool join(int u ,int v)
{
    int root_u = find_root(u);
    int root_v = find_root(v);

    if(root_u == root_v)  return false;

    if(sizeDSU[root_u] < sizeDSU[root_v])  swap(root_u , root_v);
    DSU[root_v] = root_u;
    sizeDSU[root_u] += sizeDSU[root_v];
    return true;
}

void enter()
{
    cin>> n >> m >> s;
    for(int i = 1 ; i <= m ; i++)
    {
        int u , v , c ;
        cin>> u >> v >> c;
        graph[i] = {u , v , c , i};
    }

    for(int i = 1 ; i <= n ; i++)
    {
        DSU[i] = i;
        sizeDSU[i]  = 1;
    }

}
void process()
{
    sort(graph + 1, graph + m + 1, [](node &a , node &b) {return a.price < b.price; });

    for(int i = m ; i >= 1 ; i--)   if( join(graph[i].u , graph[i].v) ) check[i] = true;

    for(int i = 1 ; i <= m ; i++)
    {
        if(!check[i] && totalErase + graph[i].price <= s)
        {
            location.push_back(graph[i].id);
            totalErase += graph[i].price;
        }
    }

    cout<<location.size()<<'\n';

    sort(location.begin() , location.end());
    for(int id : location)  cout<<id<<" ";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    enter();
    process();
    return 0;
}
