Find the Maximum Flow
Submissions: 1467   Accuracy:

22.57%

  Difficulty: Hard   Marks: 8

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.

Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. The first line of each test case contains two space separated integers N and M . Then in the next line are M space separated triplets x, y, z denoting an undirected edge from x to y with a flow capacity of z.

Output:
For each test case in a new line print a single integer denoting the maximum flow between 1 to N.

Constraints:
1<=T<=100
1<=N,M<=1000

Example:
Input:

2
5 4
1 2 1 3 2 2 4 2 3 2 5 5
4 4
1 2 8 1 3 10 2 4 2 3 4 3
Output:
1
5

** For More Input/Output Examples Use 'Expected Output' option **

Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.