Pagini recente » Cod sursa (job #2717211) | Cod sursa (job #3216726) | Cod sursa (job #1011715) | Cod sursa (job #826418) | Cod sursa (job #1881635)
#include <bits/stdc++.h>
#define NMAX 1005
#define INF 1e9
using namespace std;
ifstream fin("critice.in");
ofstream fout("critice.out");
struct point{
int c,f;
};
vector < int > G[NMAX];
vector < pair < int , int > > E;
point F[NMAX][NMAX];
int ant[NMAX];
bool B[NMAX];
bool V[NMAX][2];
inline bool BFS(const int &N){
int nod;
memset(B,0,sizeof(B));
B[1] = 1;
queue < int > Q;
Q.push(1);
while(!Q.empty()){
nod = Q.front();
Q.pop();
for(auto const &it : G[nod]){
if(B[it] == 1 || F[nod][it].c == F[nod][it].f) continue;
B[it] = 1;
ant[it] = nod;
if(it == N)
return 1;
Q.push(it);
}
}
return 0;
}
void DFS(const int &nod,const int &n){
V[nod][n] = 1;
for(auto const &it : G[NMAX]){
if(!V[it][n] && F[nod][it].c > F[nod][it].f){
DFS(it,n);
}
}
}
int main()
{
ios :: sync_with_stdio(false);
fin.tie(NULL);
int n,m,x,y,c,mflow;
fin >> n >> m;
for(int i = 1; i <= m; i++){
fin >> x >> y >> c;
G[x].push_back(y);
G[y].push_back(x);
F[x][y].c = c;
F[y][x].c = c;
E.push_back({x,y});
}
while(BFS(n)){
for(auto const &it : G[n]){
if(B[it] == 0 || F[it][n].c == F[it][n].f) continue;
mflow = INF;
ant[n] = it;
for(int j = n; j != 1; j = ant[j])
mflow = min(mflow,F[ant[j]][j].c - F[ant[j]][j].f);
if(mflow == 0) continue;
for(int j = n; j != 1; j = ant[j]){
F[ant[j]][j].f += mflow;
F[j][ant[j]].f -= mflow;
}
}
}
DFS(1,0);
DFS(n,1);
int i = 0;
vector < int > S;
for(auto const &it : E){
i++;
if((F[it.first][it.second].f == F[it.first][it.second].c || F[it.second][it.first].f == F[it.second][it.first].c) && ((V[it.first][0] && V[it.second][1]) || (V[it.second][0] && V[it.first][1]) ))
S.push_back(i);
}
sort(S.begin(),S.end());
fout << S.size() << "\n";
for(auto const &it : S)
fout << it << "\n";
return 0;
}