Cod sursa(job #211531)
//#include <cstdio>
#include <fstream>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#define vv 1001
#define minim(x,y) ((x)<(y)?(x):(y))
using namespace std;
ifstream fin("critice.in");
ofstream fout("critice.out");
int c[vv][vv],f[vv][vv],v[vv],d[vv][vv];
int n,m;
queue <int> q,w,aa;
stack <int> s;
vector <int> l;
void citire()
{
//freopen("critice.in","r",stdin);
//scanf("%d%d", &n, &m);
fin >> n >> m;
int x,y;
for (int i=1; i<=m; i++)
{
//scanf("%d%d", &x, &y);
//scanf("%d", &c[x][y]);
fin >> x >> y;
fin >> c[x][y];
c[y][x]=c[x][y];
d[x][y]=d[y][x]=i;
}
}
int bf(int st,int w)
{
q.push(st);
memset(v,0,sizeof(v));
v[1]=st;
int e;
while (!q.empty())
{
e=q.front();
q.pop();
for (int i=1; i<=n; i++)
if (f[e][i]<c[e][i] && !v[i])
{
v[i]=e;
q.push(i);
}
}
return v[w];
}
void flux()
{
int a=20000;
int nod=n;
while (nod!=1)
{
a=minim(a,c[nod][v[nod]]-f[nod][v[nod]]);
s.push(nod);
nod=v[nod];
}
nod=1;
while (!s.empty())
{
f[nod][s.top()]+=a;
f[s.top()][nod]=f[nod][s.top()];
if (f[nod][s.top()]==c[nod][s.top()])
{
aa.push(nod);
int t=s.top();
w.push(t);
c[nod][s.top()]=c[s.top()][nod]=0;
}
nod=s.top();
s.pop();
}
}
void critice()
{
while (!w.empty())
{
int p=aa.front();
int o=w.front();
aa.pop();
w.pop();
if (p==1 && bf(o,n))
l.push_back(d[p][o]);
else
if (o==1 && bf(p,n))
l.push_back(d[p][o]);
else
if (p==n && bf(1,o))
l.push_back(d[p][o]);
else
if (o==n && bf(1,p))
l.push_back(d[p][o]);
else
if ((bf(1,p) && bf(o,n)) || (bf(1,o) && bf(p,n)))
l.push_back(d[p][o]);
}
sort(l.begin(),l.end());
//printf("%d\n", l.size());
fout << l.size() << "\n";
for (vector <int> ::iterator it=l.begin(); it!=l.end(); it++)
// printf("%d\n", *it);
fout << *it;
}
int main()
{
citire();
while (bf(1,n))
flux();
//freopen("critice.out","w",stdout);
critice();
return 0;
}