{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003esection pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n}\u003c/style\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv id\u003d\"problem-body\" class\u003d\"\"\u003e\n\t\t\t\u003cdiv class\u003d\"col-md-12\"\u003e\n\t\t\t\t\u003csection id\u003d\"description\" class\u003d\"problem-section\"\u003e\n\t\t\t\t\u003cdiv class\u003d\"headline\"\u003e\n\t\t\t\t\u003ch2\u003e题目描述\u003c/h2\u003e\n\t\t\t\t\u003c/div\u003e\n\t\t\t\t\u003cdiv id\u003d\"problem_description\" class\u003d\"problem-text\"\u003e\n\t\t\t\t\u003cp\u003e树(tree)是一种无环的无向图。在树中,无论选择哪两个节点,它们之间的路径始终只有一条。在树中,可能存在一种情况,选择两个节点并将它们向两侧拉伸,使得树的所有节点都位于以这两个节点为直径端点的圆内。\u003c/p\u003e\n\n\u003cp\u003e\u003cimg alt\u003d\"\" height\u003d\"123\" src\u003d\"CDN_BASE_URL/d500a68d40be457690cb644c98282dfd?v\u003d1706268158\" width\u003d\"310\"\u003e\u003c/p\u003e\n\n\u003cp\u003e这两个节点之间路径的长度被称为树的直径。准确地说,它是指树中所有路径中最长的那个。\u003c/p\u003e\n\n\u003cp\u003e给定一棵带有根节点的树,以及带有边权重的边,编写程序以计算并输出树的直径。如果给定如下树,则树的直径为45。\u003c/p\u003e\n\n\u003cp\u003e\u003cimg alt\u003d\"\" height\u003d\"152\" src\u003d\"CDN_BASE_URL/719d666c582f6c12a5d938d23f173b44?v\u003d1706268158\" width\u003d\"312\"\u003e\u003c/p\u003e\n\n\u003cp\u003e树的节点从1到n进行编号。\u003c/p\u003e\n\t\t\t\t\u003c/div\u003e\n\t\t\t\t\u003c/section\u003e\n\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\t\t\t\t\u003cdiv class\u003d\"col-md-12\"\u003e\n\t\t\t\t\t\u003csection id\u003d\"input\" class\u003d\"problem-section\"\u003e\n\t\t\t\t\t\u003cdiv class\u003d\"headline\"\u003e\n\t\t\t\t\t\u003ch2\u003e输入\u003c/h2\u003e\n\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\u003cdiv id\u003d\"problem_input\" class\u003d\"problem-text\"\u003e\n\t\t\t\t\t\u003cp\u003e文件的第一行包含节点数n(1 ≤ n ≤ 10,000)。接下来的n-1行包含每条边的信息。每条边的信息由三个整数组成。第一个整数表示连接的两个节点中父节点的编号,第二个整数表示子节点的编号,第三个整数表示边的权重。边的信息按照父节点编号升序排列,若父节点编号相同,则按子节点编号升序排列。根节点的编号始终为1,边的权重为不超过100的正整数。\u003c/p\u003e\n\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\u003c/section\u003e\n\t\t\t\t\u003c/div\u003e\n\t\n\t\t\t\t\u003cdiv class\u003d\"col-md-12\"\u003e\n\t\t\t\t\t\u003csection id\u003d\"output\" class\u003d\"problem-section\"\u003e\n\t\t\t\t\t\u003cdiv class\u003d\"headline\"\u003e\n\t\t\t\t\t\u003ch2\u003e输出\u003c/h2\u003e\n\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\u003cdiv id\u003d\"problem_output\" class\u003d\"problem-text\"\u003e\n\t\t\t\t\t\u003cp\u003e输出树的直径。\u003c/p\u003e\n\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\u003c/section\u003e\n\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\u003cdiv class\u003d\"col-md-12\"\u003e\n\t\t\t\u003csection id\u003d\"limit\" style\u003d\"display:none;\" class\u003d\"problem-section\"\u003e\n\t\t\t\u003cdiv class\u003d\"headline\"\u003e\n\t\t\t\u003ch2\u003e限制\u003c/h2\u003e\n\t\t\t\u003c/div\u003e\n\t\t\t\u003cdiv id\u003d\"problem_limit\" class\u003d\"problem-text\"\u003e\n\t\t\t\t\t\t\u003c/div\u003e\n\t\t\t\u003c/section\u003e\n\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\u003cdiv class\u003d\"col-md-12\"\u003e\n\t\t\t\t\u003cdiv class\u003d\"row\"\u003e\n\t\t\t\t\t\u003cdiv\u003e\u003ch2\u003e示例1\u003c/h2\u003e\u003ctable class\u003d\"vjudge_sample\"\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\u003e12\n1 2 3\n1 3 2\n2 4 5\n3 5 11\n3 6 9\n4 7 1\n4 8 7\n5 9 15\n5 10 4\n6 11 6\n6 12 10\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e45\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\u003c/div\u003e\n\t\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\t\t\t\t\u003cdiv class\u003d\"col-md-12\"\u003e\n\t\t\t\t\u003csection id\u003d\"hint\" style\u003d\"display: none;\" class\u003d\"problem-section\"\u003e\n\t\t\t\t\u003cdiv class\u003d\"headline\"\u003e\n\t\t\t\t\u003ch2\u003e提示\u003c/h2\u003e\n\t\t\t\t\u003c/div\u003e\n\t\t\t\t\u003cdiv id\u003d\"problem_hint\" class\u003d\"problem-text\"\u003e\n\t\t\t\t\n\t\t\t\t\u003c/div\u003e\n\t\t\t\t\u003c/section\u003e\n\t\t\t\u003c/div\u003e\n\t\t\t\t\t\t\t\t\u003c/div\u003e"}}]}