{"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 让我们称具有$n$个顶点和m条边的加权连通无向图为KD-Graph,如果满足以下条件:\n \u003cbr\u003e\n \u003cbr\u003e\n * $n$个顶点严格分成$K$组,每组至少包含一个顶点\n \u003cbr\u003e\n \u003cbr\u003e\n * 如果顶点$p$和$q$($p$ ≠ $q$)在同一组中,则$p$和$q$之间必须至少有一条路径满足此路径上的最大值小于等于$D$\n \u003cbr\u003e\n \u003cbr\u003e\n * 如果顶点$p$和$q$($p$ ≠ $q$)在不同的组中,则$p$和$q$之间不能有任何路径满足此路径上的最大值小于等于$D$\n \u003cbr\u003e\n \u003cbr\u003e\n 给定一张具有$n$个顶点和$m$条边的加权连通无向图$G$和一个整数$K$。\n \u003cbr\u003e\n \u003cbr\u003e\n 你的任务是找出最小的非负整数$D$,使得存在一种方法将这$n$个顶点分成$K$组,使得$G$满足KD-Graph的定义。如果找不到这样的$D$,则输出$-1$。\n\u003c/div\u003e"}},{"title":"输入","value":{"format":"HTML","content":"第一行包含一个整数$T$(1≤ $T$ ≤5),表示测试用例的数量。\n\u003cbr\u003e\n对于每个测试用例,第一行包含三个整数$n,m,k(2≤n≤100000,1≤m≤500000,1≤k≤n)$。\n\u003cbr\u003e\n接下来的每一行包含三个整数$u, v$和$c$ $(1≤v,u≤n,v≠u,1≤c≤10^9)$,表示顶点$u$和$v$之间存在一条权重为$c$的边。"}},{"title":"输出","value":{"format":"HTML","content":"对于每个测试用例,在新的一行中打印一个整数。"}},{"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\u003e2\r\n3 2 2\r\n1 2 3\r\n2 3 5\r\n3 2 2\r\n1 2 3\r\n2 3 3\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\r\n-1\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}}]}