JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
maxflow problem | Reply
Hi folks,
I 've used DFS to find MAXFLOW between X and Y.
Note: I 've stored graph in matrix form.

void fun(int x,int y,int p_cost)
{
if(y==Y)
{

cost[x]=cost[x] < p_cost ? p_cost : cost[x];
return ;
}

for(int i=0;i<n;i++)
{
if(g[y][i]>0)
{
fun(y,i,p_cost > g[y][i] ? g[y][i] : p_cost);
}
}
}

And in main() :
fun(X,X,99999999);
int result=0;
for(int i=0;i<cost.size();i++)
result+=cost[i];
cout><<result<<endl;


Is not it the simplest way for the problem?>
RSS