{"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":"MD","content":"有一棵包含N个节点的树,树的节点从1到N标号。 每一个节点有一个权值,权值均为整数。\n\n我们将要求您回答以下询问: \n u v:询问你从 u 到 v 的路径上有多少个权值互不同的节点。\n\n"}},{"title":"Input","value":{"format":"MD","content":"第一行有两个整数N和M. (N \u0026lt;\u003d 40000, M \u0026lt;\u003d 100000)\n\n第二行有N个整数。第i个整数表示第i个点的权值\n\n接下来的N-1行,每行有两个整数u v,它代表了一条边 (u, v)。\n \n接下来的M行,每行有两个整数u v,表示询问从u到v的路径上有多少个权值互不相同的节点。\n "}},{"title":"Output","value":{"format":"MD","content":"对于每次询问,输出它的结果"}},{"title":"Sample Input","value":{"format":"MD","content":"\u003cpre\u003e8 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"}},{"title":"Sample Output","value":{"format":"MD","content":"\u003cpre\u003e4\n4\u003c/pre\u003e "}}]}