One and only flow
Practice
3 (7 votes)
Algorithms
Depth first search
Graphs
Strongly connected component
Problem
77% Success 2113 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a network of directed graph of \(N\) vertices and \(M\) edges, where every edges' capacity is \(1\). An ordered pair \((u, v), u\not=v\) is good, if the maxflow is exactly \(1\) upon setting \(u\) as the source vertex and \(v\) as the sink vertex of the flow network. Find out if all of the ordered pairs \((u, v), u \not= v\) are good or not.

Note

  • For ordered pairs, if \(x \not=y,\) then \((x, y) \not= (y, x)\).
  • Flow Network

Input format

  • First line: An integer \(T\) - number of testcases.
  • Each test case's-
    • First line: Two integers \(N, M\).
    • \(i\)-th of the next \(M\) lines: two integers \(u_i, v_i\)- a directed edge from \(u_i\) to \(v_i\).

Output format

Print \(T\) lines- \(i\)-th line contains answer for \(i\)-th testcase. For a testcase, the answer is "Yes" if every ordered pair is good, "No" otherwise.

Constraints

  • \(1 \le T \le 600000\)
  • \(1 \le N \le 200000\)
  • \(0 \le M \le 500000\)
  • \(\sum N \le 600000\)
  • \(\sum M \le 1500000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
AlgorithmsDepth First SearchGraphsGreedy AlgorithmsMediumSortingTrees
Points:30
5 votes
Tags:
AlgorithmsDepth First SearchGraphsMedium
Points:30
8 votes
Tags:
AlgorithmsCombinatoricsDepth First SearchGraphsMedium