{"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$$$ 个节点,它们被编号为 $$$1, \\dots, n$$$。编号为 $$$1$$$ 的节点是树的根。此外,每个节点 $$$i$$$ 都被赋予一个编号 $$$a_i$$$。你惊讶地发现,有几对节点 $$$(i, j)$$$ 满足 $$$$$$a_i \\oplus a_j \u003d a_{\\operatorname{lca}(i, j)},$$$$$$,其中 $$$\\oplus$$$ 表示按位异或运算,$$$\\operatorname{lca}(i, j)$$$ 是 $$$i$$$ 和 $$$j$$$ 的最低公共祖先,或者正式地说,是同时拥有 $$$i$$$ 和 $$$j$$$ 作为后代的最低(即最深的)节点。\u003c/p\u003e\u003cp\u003e不幸的是,你记不得所有这样的对,只记得满足上述条件的所有不同节点对 $$$i \\oplus j$$$ 的总和。注意,在这里 $$$(i, j)$$$ 和 $$$(j, i)$$$ 被视为相同。换句话说,你只能回忆起 $$$$$$\\sum\\limits_{i\u003d1}^n\\sum\\limits_{j\u003di+1}^n [a_i \\oplus a_j \u003d a_{\\operatorname{lca}(i, j)}] (i \\oplus j).$$$$$$。\u003c/p\u003e\u003cp\u003e现在你需要计算它,以便将来更好地记住。\u003c/p\u003e"}},{"title":"输入","value":{"format":"HTML","content":"\u003cp\u003e第一行包含一个整数 $$$n$$$ ($$$2 \\leq n \\leq 10^5$$$)。\u003c/p\u003e\u003cp\u003e第二行包含 $$$n$$$ 个整数,$$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 10^6$$$)。\u003c/p\u003e\u003cp\u003e接下来的 $$$n - 1$$$ 行中,每行包含 $$$2$$$ 个整数 $$$u$$$ 和 $$$v$$$ ($$$1 \\leq u, v \\leq n, u \\neq v$$$),表示 $$$u$$$ 和 $$$v$$$ 之间有一条边。保证这些边构成一棵树。\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\u003e6\n4 2 1 6 6 5\n1 2\n2 3\n1 4\n4 5\n4 6\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"}}]}