{"trustable":true,"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\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e给定一个无向图,包含$$$n$$$个顶点。每个顶点上都写着一个数字;顶点$$$i$$$上的数字是$$$a_i$$$。最开始图中没有边。\u003c/p\u003e\u003cp\u003e你可以向这个图中添加一些边,但是你需要支付费用。连接顶点$$$x$$$和$$$y$$$的边的费用是$$$a_x + a_y$$$个硬币。此外还有$$$m$$$个特殊优惠,每个都用三个数字$$$x$$$、$$$y$$$和$$$w$$$表示,意味着你可以连接顶点$$$x$$$和$$$y$$$并支付$$$w$$$个硬币。你不一定要使用特殊优惠:如果有一对顶点$$$x$$$和$$$y$$$与特殊优惠相关联,你仍然可以连接这两个顶点,支付$$$a_x + a_y$$$个硬币。\u003c/p\u003e\u003cp\u003e你需要花费多少硬币才能使图连通?回想一下,一个图是连通的,如果从任意一个顶点到另一个顶点都可以只使用属于该图的边到达。\u003c/p\u003e"}},{"title":"输入","value":{"format":"HTML","content":"\u003cp\u003e第一行包含两个整数$$$n$$$和$$$m$$$($$$1 \\le n \\le 2 \\cdot 10^5$$$,$$$0 \\le m \\le 2 \\cdot 10^5$$$) — 图中顶点的数量和特殊优惠的数量。\u003c/p\u003e\u003cp\u003e第二行包含$$$n$$$个整数$$$a_1, a_2, \\dots, a_n$$$($$$1 \\le a_i \\le 10^{12}$$$) — 写在顶点上的数字。\u003c/p\u003e\u003cp\u003e接下来有$$$m$$$行,每行包含三个整数$$$x$$$、$$$y$$$和$$$w$$$($$$1 \\le x, y \\le n$$$、$$$1 \\le w \\le 10^{12}$$$、$$$x \\ne y$$$)表示一个特殊优惠:你可以连接顶点$$$x$$$和顶点$$$y$$$,这条边的费用是$$$w$$$个硬币。\u003c/p\u003e"}},{"title":"输出","value":{"format":"HTML","content":"\u003cp\u003e输出一个整数 — 你需要支付的最少硬币数量,使图连通。\u003c/p\u003e"}},{"title":"示例1","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 2\n1 3 3\n2 3 5\n2 1 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"示例2","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\u003e4 0\n1 3 3 7\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e16\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"示例3","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\u003e5 4\n1 2 3 4 5\n1 2 8\n1 3 10\n1 4 7\n1 5 15\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e18\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"注意","value":{"format":"HTML","content":"\u003cp\u003e在第一个示例中,可以使用特殊优惠$$$2$$$将$$$1$$$连接到$$$2$$$,然后再将$$$1$$$连接到$$$3$$$,而不使用任何优惠。\u003c/p\u003e\u003cp\u003e在接下来的两个示例中,可以在不使用特殊优惠的情况下获得最优解。\u003c/p\u003e"}}]}