Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5642 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@sanskar94511 | 535 |

@akashverma4 | 291 |

@swastik8750 | 237 |

@nishunishuraj18 | 223 |

@nayan2709 | 211 |

@ajaybhardwaj1999 | 196 |

@surajmamgai | 193 |

@AnshikaPandey | 192 |

@gurshehzadsingh | 188 |

@shardul08 | 185 |

@Rajpra786 | 181 |

Complete Leaderboard |

Given a graph with N vertices numbered 1 to N and M edges, The task is to find the max flow from vertex 1 to vertex N.

**Example 1:**

**Input:**
N = 5, M = 4
Edges[]= { {1, 2, 1} , {3, 2, 2}, {4, 2, 3}, {2, 5, 5} }
**Output:**
1
**Explanation: **
1 - 2 - 3
/ \
4 5
1 unit can flow from 1 -> 2 - >5

**Example 2:**

**Input:**
N = 4 , M = 4
Edges[] = { {1, 2, 8}, {1, 3, 10}, {4, 2, 2}, {3, 4, 3} }
**Output:**
5
**Explanation:**
1 - 2
| |
3 - 4
3 unit can flow from 1 -> 3 -> 4
2 unit can flow from 1 -> 2 -> 4
Total max flow from 1 to N = 3+2=5

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function** solve()** which takes the **N **(the number of vertices) ,**M **(the number of Edges) and the array **Edges**[] (Where Edges[i] denoting an undirected edge between Edges[i][0] and Edges[i][1] with a flow capacity of Edges[i][2] ), and returns the integer denoting the maximum flow from 1 to N.

**Expected Time Complexity:** O( max_flow* M)

**Expected Auxiliary Space:** O(N+M)

Where max_flow is the maximum flow from 1 to N

**Constraints:**

1 <= N,M,Edges[i][2] <= 1000

1 <= Edges[i][0],Edges[i][1] <= N

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Find the Maximum Flow

...