2281: Strongly connected

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:11 解决:7

题目描述

Give 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 is still a simple directed graph. Also, after you add these edges, this graph must NOT be strongly connected.

输入

The first line of date is an integer T, which is the number of the text cases.
Then T cases follow, each case starts of two numbers N and M, representing the number of nodes and the number of edges, then M lines follow. Each line contains two integers x and y, means that there is a edge from x to y.

输出

For each case, you should output the maximum number of the edges you can add.
If the original graph is strongly connected, just output -1.

样例输入 复制

3
3 3
1 2
2 3
3 1
3 3
1 2
2 3
1 3
6 6
1 2
2 3
3 1
4 5
5 6
6 4

样例输出 复制

Case 1: -1
Case 2: 1
Case 3: 15

来源/分类