Pagini recente » Cod sursa (job #2399694) | Cod sursa (job #438345) | Cod sursa (job #1368692) | Cod sursa (job #777063) | Cod sursa (job #2301404)
#include <bits/stdc++.h>
#define N 1005
using namespace std;
ifstream in("critice.in");
ofstream out("critice.out");
int n,m,graph[N][N],pater[N],v[N],flow[N][N];
struct edge{
int x;
int y;
};
edge lop[5*N];
vector <int> lista[N];
deque <int> q;
bool BFS(int node)
{
memset(pater,-1,sizeof(pater));
pater[node]=0;
q.push_back(node);
while(!q.empty())
{
int p=q.front();
q.pop_front();
for(auto x:lista[p])
{
if(pater[x]==-1 && graph[p][x]>flow[p][x])
{
pater[x]=p;
q.push_back(x);
}
}
}
if(pater[n]!=-1)
return true;
return false;
}
int main()
{
in >> n >> m;
for(int i=1; i<=m;i++)
{
in >> lop[i].x >> lop[i].y;
in >> graph[lop[i].x][lop[i].y];
graph[lop[i].y][lop[i].x]=graph[lop[i].x][lop[i].y];
lista[lop[i].x].push_back(lop[i].y);
lista[lop[i].y].push_back(lop[i].x);
}
while(BFS(1))
{
for(auto x:lista[n])
{
if(x==-1)continue;
int path=graph[x][n]-flow[x][n];
for(int i=x; i!=1; i=pater[i])
{
int u=pater[i];
path=min(path,graph[u][i]-flow[u][i]);
}
flow[x][n]+=path;
flow[n][x]=flow[x][n];
for(int i=x; i!=1; i=pater[i])
{
int u=pater[i];
flow[u][i]+=path;
flow[i][u]=flow[u][i];
}
}
}
int nr=0;
for(int i=1; i<=m; i++)
{
graph[lop[i].x][lop[i].y]++;
graph[lop[i].y][lop[i].x]++;
if(BFS(1))
{
v[++nr]=i;
}
graph[lop[i].x][lop[i].y]--;
graph[lop[i].y][lop[i].x]--;
}
out << nr << '\n';
for(int i=1; i<=nr; i++)
out << v[i] <<'\n';
return 0;
}