{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e给定一个包含 N 个节点和 M 条边的简单有向图。请告诉我,在保持图仍然是简单有向图的前提下,最多可以添加多少条边。同时,在添加这些边之后,该图必须不是强连通的。\u003cbr\u003e\u003cstrong\u003e简单有向图是指没有重复边或环路的有向图。\u003cbr\u003e强连通有向图是指可以从任意一个节点出发,沿着边的方向到达图中的任意其他节点的有向图。\u003cbr\u003e\u003c/strong\u003e\u003c/div\u003e"}},{"title":"输入","value":{"format":"HTML","content":"第一行是一个整数 T,表示测试用例的数量。\u003cbr\u003e接下来是 T 个测试用例,每个测试用例的第一行包含两个整数 N 和 M(1≤N≤100000,1≤M≤100000),分别表示节点的数量和边的数量,然后是 M 行数据。每行包含两个整数 x 和 y,表示从节点 x 到节点 y 之间有一条边。"}},{"title":"输出","value":{"format":"HTML","content":"对于每个测试用例,你需要输出可以添加的最大边数。\u003cbr\u003e如果原图是强连通的,则输出 -1。"}},{"title":"示例","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\r\n3 3\r\n1 2\r\n2 3\r\n3 1\r\n3 3\r\n1 2\r\n2 3\r\n1 3\r\n6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1: -1\r\nCase 2: 1\r\nCase 3: 15\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}}]}