# Changliantong (hdu4635) up to a few unidirectional edges to satisfy the final graph is not strongly connected

Source: Internet
Author: User

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

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.