{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\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 type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"给你一个有 n 个节点和 m 条边的无向图,节点编号1到n\n当且仅当以下条件成立时,该图被认为是和谐的:\n对于任意1 ≤ l \u003c m \u003c r ≤ n 三个整数(l,m,r)如果存在 l 到 r 的路径,则也存在 l 到 m 的路径\n也就是对于 一对 l 和 r 如果 l 到 r 有路径\n则 l 到 (l+1),(l+2)......(l+r-1) 也存在路径\n要使此图变成和谐,最少需要添加多少边?"}},{"title":"Input","value":{"format":"MD","content":"第一行2个整数 n 和 m (3≤n≤200 000 and 1≤m≤200 000).\n接下来 m 行 每行2个整数 u 和 v (1≤u,v≤n, u≠v) 代表 u 和 v 之间有一条边 \n保证没有自环,2个节点之间最多只有一条边"}},{"title":"Output","value":{"format":"MD","content":"输出最少需要添加边的数量"}},{"title":"Examples","value":{"format":"MD","content":"\u003cdiv class\u003d\"sample-test\"\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e14 8\n1 2\n2 7\n3 4\n6 3\n5 7\n3 8\n6 8\n11 12\n\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e1\n\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e200000 3\n7 9\n9 8\n4 5\n\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e0\n\u003c/pre\u003e\n \u003c/div\u003e\n\u003c/div\u003e"}},{"title":"Note","value":{"format":"MD","content":"\u003cp\u003eIn the first example, the given graph is not harmonious (for instance, 1 \u0026lt; 6 \u0026lt; 7, node 1 can reach node 7 through the path 1 \\rightarrow 2 \\rightarrow 7, but node 1 can\u0027t reach node 6). However adding the edge (2, 4) is sufficient to make it harmonious.\u003c/p\u003e\n\u003cp\u003eIn the second example, the given graph is already harmonious.\u003c/p\u003e"}}]}