Pagini recente » Cod sursa (job #2478991) | Cod sursa (job #2710282) | Cod sursa (job #2602525) | Cod sursa (job #2067270) | Cod sursa (job #2123527)
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
ofstream fout ("critice.out" );
ifstream fin ("critice.in" );
pair < pair < int , int > , int > muc[10005];
vector < int > w[1005],ans;
int n,m,i,S,D,a,b,nod,aux,ok,mini;
int flux[1005][1005],cap[1005][1005],parent[1005],vizS[1005],vizD[1005];
inline void bfs()
{
queue < int > q;
q.push( S );
memset( parent , 0 , sizeof( parent ) );
parent[ S ] = -1;
while( q.size() )
{
aux = q.front();
q.pop();
for( auto it : w[ aux ] )
{
if( cap[ aux ][ it ] == flux[ aux ][ it ] )
continue;
if( parent[ it ] == 0 && it != D )
{
parent[ it ] = aux;
q.push( it );
}
else if( it == D )
ok = 1;
}
}
}
inline void dinitz()
{
do
{
ok = 0;
bfs();
for( auto it : w[ D ] )
{
mini = 1e9;
if( cap[ it ][ D ] != flux[ it ][ D ] && parent[ it ] )
parent[ D ] = it;
else
continue;
for( nod = D ; nod != S ; nod = parent[ nod ] )
mini = min( mini , cap[ parent[ nod ] ][ nod ] - flux[ parent[ nod ] ][ nod ] );
for( nod = D ; nod != S ; nod = parent[ nod ] )
{
flux[ parent[ nod ] ][ nod ] += mini;
flux[ nod ][ parent[ nod ] ] += mini;
}
}
}while( ok );
}
void DFSS( int nod )
{
vizS[ nod ] = 1;
for( auto it : w[ nod ] )
if( cap[ nod ][ it ] != flux[ nod ][ it ] && vizS[ it ] == 0 )
DFSS( it );
}
void DFSD( int nod )
{
vizD[ nod ] = 1;
for( auto it : w[ nod ] )
if( cap[ nod ][ it ] != flux[ nod ][ it ] && vizD[ it ] == 0 )
DFSD( it );
}
int main()
{
fin>>n>>m;
for( i = 1 ; i <= m ; i++ )
{
fin>>muc[ i ].x.x>>muc[ i ].x.y>>muc[ i ].y;
w[ muc[ i ].x.x ].push_back( muc[ i ].x.y );
w[ muc[ i ].x.y ].push_back( muc[ i ].x.x );
cap[ muc[ i ].x.x ][ muc[ i ].x.y ] = muc[ i ].y;
cap[ muc[ i ].x.y ][ muc[ i ].x.x ] = muc[ i ].y;
}
S = 1;
D = n;
dinitz();
DFSS( S );
DFSD( D );
for( i = 1 ; i <= m ; i++ )
{
a = muc[ i ].x.x;
b = muc[ i ].x.y;
if( flux[ a ][ b ] == cap[ a ][ b ] && ( vizS[ a ] && vizD[ b ] ) )
ans.push_back( i );
}
fout<<ans.size()<<'\n';
for( auto it : ans )
fout<<it<<'\n';
return 0;
}