Strongly connected
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1802 Accepted Submission (s): 746
Problem descriptiongive A simple directed graph with N nodes and M edges. Please tell me the maximum number of the edges you can add that the graph was still a simple directed graph. Also, after you add these edges, the this graph must isn't be strongly connected.
a simple directed graph was a directed graph having no multiple edges or graph loops.
A strongly connected digraph is a directed graph in which it's possible to reach all node starting from all other node by Traversing edges in the direction (s) in which they point.
Inputthe first line of date is a integer T, which is the number of the text cases.
Then T cases follow, each case starts of the numbers N and M, 1<=n<=100000, 1<=m<=100000, representing the NUM ber of nodes and the number of edges, then M lines follow. Each line contains the integers x and y, means that there was a edge from X to Y.
Outputfor the should output the maximum number of the edges you can add.
If The original graph is strongly connected, just output-1.
Sample Input33 31 22 33 13 31 22 31 36 61 22 33 14 55 66 4
Sample outputcase 1: -1case 2:1case 3:15
Changliantong (hdu4635) up to a few unidirectional edges to satisfy the final graph is not strongly connected