Pagini recente » Cod sursa (job #613034) | Cod sursa (job #2520345) | Cod sursa (job #2276271) | Cod sursa (job #2791175) | Cod sursa (job #1145490)
using namespace std;
#include <fstream>
#include <utility>
#include <vector>
#include <typeinfo>
#include <queue>
#include <cstring>
#define a first
#define b second
#define pb push_back
#define mp make_pair
#define NMAX 1005
#define MMAX 10005
#define INF 999999999
#define foreach(V) for(vector<int>::iterator it = (V).begin(); it < (V).end(); ++it)
typedef pair<int,int> Edge;
FILE* f=freopen("critice.in","r",stdin);
FILE* o=freopen("critice.out","w",stdout);
int n,m;
vector<int> G[NMAX];
Edge edg[MMAX];
int cap[NMAX][NMAX];
int flw[NMAX][NMAX];
int father[NMAX];
int BFS()
{
queue<int> q;
memset(father,0,sizeof(father));
q.push(1);
father[1]=-1;
while(!q.empty())
{
int where=q.front();
q.pop();
if(where==n) continue;
foreach(G[where])
{
if(cap[where][*it]==flw[where][*it]||father[*it]) continue;
father[*it]=where;
q.push(*it);
}
}
return father[n];
}
inline int minim(int a,int b) { return (a<b)?a:b; }
void MaxFlow()
{
while(BFS())
{
int node;
foreach(G[n])
{
if(cap[*it][n]==flw[*it][n]||!father[*it]) continue;
int minflow=INF;
for(node=n;node!=1;node=father[node])
{
int ft=father[node];
minflow=minim(minflow,cap[ft][node]-flw[ft][node]);
}
if(!minflow) continue;
for(node=n;node!=1;node=father[node])
{
int ft=father[node];
flw[ft][node]+=minflow;
flw[node][ft]-=minflow;
}
}
}
}
bool color[NMAX];
void ApplyColor(int x)
{
color[x]=1;
foreach(G[x])
{
if(!color[*it]&&cap[x][*it]!=flw[x][*it])
ApplyColor(*it);
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<m;++i)
{
int x,y,c;
scanf("%d%d%d",&x,&y,&c);
G[x].pb(y);
G[y].pb(x);
cap[x][y]=cap[y][x]=c;
edg[i]=mp(x,y);
}
MaxFlow();
ApplyColor(1);
vector<int> sol;
for(int i=0;i<m;++i)
{
if(color[edg[i].a]!=color[edg[i].b])
sol.pb(i+1);
}
printf("%d\n",sol.size());
foreach(sol)
printf("%d\n",*it);
return 0;
}