One and only flow

3

7 votes
Algorithms, Depth First Search, Graphs, Strongly connected component
Problem

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),uv 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),uv are good or not.

Note

  • For ordered pairs, if xy, then (x,y)(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 ui,vi- a directed edge from ui to vi.

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

  • 1T600000
  • 1N200000
  • 0M500000
  • N600000
  • M1500000
Sample Input
2
3 3
1 2
2 3
1 3
2 2
1 2
2 1
Sample Output
No
Yes
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

First testcase:
1st testcase graph

maxflow(23)=maxflow(12)=1, but,maxflow(31)=maxflow(32)=maxflow(21)=0,maxflow(13)=2

Second testcase:
2nd testcase graph
All ordered pairs' maxflow is 1.

Editor Image

?