{"trustable":false,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e 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 }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003chtml\u003e\n \u003chead\u003e\u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id\u003d\"problem-body\"\u003e \n \u003cp\u003e有一棵包含\u0026nbsp;\u003cstrong\u003eN\u003c/strong\u003e\u0026nbsp;个节点的树。 树的节点从\u0026nbsp;\u003cstrong\u003e1\u003c/strong\u003e\u0026nbsp;到\u0026nbsp;\u003cstrong\u003eN\u003c/strong\u003e标号。 每一个节点有一个权值,权值均为整数。\u003c/p\u003e \n \u003cp\u003e我们将要求您回答以下询问:\u003c/p\u003e \n \u003cul\u003e \n \u003cli\u003e\u003cstrong\u003eu v\u003c/strong\u003e\u0026nbsp;: 询问你从 \u003cstrong\u003eu\u003c/strong\u003e 到 \u003cstrong\u003ev\u003c/strong\u003e的路径上有多少个权值互不同的节点。\u003c/li\u003e \n \u003c/ul\u003e \n \u003ch3\u003e输入\u003c/h3\u003e \n \u003cp\u003e第一行有两个整数\u0026nbsp;\u003cstrong\u003eN\u003c/strong\u003e\u0026nbsp;和\u0026nbsp;\u003cstrong\u003eM\u003c/strong\u003e. (\u003cstrong\u003eN\u003c/strong\u003e \u0026lt;\u003d 40000, \u003cstrong\u003eM\u003c/strong\u003e \u0026lt;\u003d 100000)\u003c/p\u003e \n \u003cp\u003e第二行有\u0026nbsp;\u003cstrong\u003eN\u003c/strong\u003e\u0026nbsp;个整数。第i个整数表示第i个点的权值\u003c/p\u003e \n \u003cp\u003e接下来的\u0026nbsp;\u003cstrong\u003eN-1\u003c/strong\u003e\u0026nbsp;行,每行有两个整数\u0026nbsp;\u003cstrong\u003eu\u003c/strong\u003e\u0026nbsp;\u003cstrong\u003ev\u003c/strong\u003e,它代表了一条边 (\u003cstrong\u003eu\u003c/strong\u003e, \u003cstrong\u003ev\u003c/strong\u003e)。\u003c/p\u003e \n \u003cp\u003e接下来的\u0026nbsp;\u003cstrong\u003eM\u003c/strong\u003e\u0026nbsp;行,每行有两个整数\u0026nbsp;\u003cstrong\u003eu\u003c/strong\u003e\u0026nbsp;\u003cstrong\u003ev\u003c/strong\u003e,表示询问从\u0026nbsp;\u003cstrong\u003eu\u003c/strong\u003e\u0026nbsp;到\u0026nbsp;\u003cstrong\u003ev\u003c/strong\u003e的路径上有多少个权值互不相同的节点。\u003c/p\u003e \n \u003ch3\u003e输出\u003c/h3\u003e \n \u003cp\u003e对于每次询问,输出它的结果:\u003c/p\u003e \n \u003ch3\u003e样例\u003c/h3\u003e \n \u003cpre\u003e\u003cstrong\u003e输入:\u003c/strong\u003e\n8 2\n105 2 9 3 8 5 7 7\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n4 8\n2 5\n7 8\u003c/pre\u003e \n \u003cpre\u003e\u003cstrong\u003e输出:\u003c/strong\u003e\n4\n4\u003c/pre\u003e \n \u003c/div\u003e\n \u003c/body\u003e\n\u003c/html\u003e"}}]}