{"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\u003eChitanda owns a farm with $$$n$$$ apple trees on it, labeled by $$$1,2,\\dots,n$$$, the $$$i$$$-th apple tree has $$$a_i$$$ apples. There are $$$n-1$$$ bidirectional roads connecting them. For all $$$i\u0026gt;1$$$, an apple tree number $$$i$$$ is connected by a road to the apple tree number $$$\\lfloor\\frac{i}{2}\\rfloor$$$. So the map of the farm is also like a tree.\u003c/p\u003e\u003cp\u003eApple business is booming. There are $$$m$$$ requests, labeled by $$$1,2,\\dots,m$$$. For the $$$i$$$-th request, Chitanda can sell the customer at most $$$c_i$$$ apples, and the customer will pay $$$w_i$$$ dollars for each apple. Unfortunately, different customers have different preferences. Specifically, for the $$$i$$$-th request, the customer will give two integers $$$u_i$$$ and $$$v_i$$$, denoting he only accepts apples from trees on the shortest path from the $$$u_i$$$-th apple tree to the $$$v_i$$$-th apple tree on the map(include $$$u_i$$$ and $$$v_i$$$).\u003c/p\u003e\u003cp\u003eAssume the root of the map is the $$$1$$$-th apple tree. It is amazing that $$$u_i$$$ is always $$$v_i$$$\u0027s ancestor or $$$u_i\u003dv_i$$$.\u003c/p\u003e\u003cp\u003eThe farm may not be able to sell $$$c_i$$$ apples to each customer. Please write a program to help Chitanda sell apples that will maximize his profits.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of the input contains an integer $$$T(1\\leq T\\leq 1000)$$$, denoting the number of test cases.\u003c/p\u003e\u003cp\u003eIn each test case, there are two integers $$$n,m(1\\leq n,m\\leq 100000)$$$ in the first line, denoting the number of apple trees and requests.\u003c/p\u003e\u003cp\u003eIn the second line, there are $$$n$$$ integers $$$a_1,a_2,...,a_n(1\\leq a_i\\leq 10^9)$$$, denoting the number of apples on each apple tree.\u003c/p\u003e\u003cp\u003eFor the next $$$m$$$ lines, each line contains four integers $$$u_i,v_i,c_i,w_i(1\\leq u_i,v_i\\leq n,1\\leq c_i\\leq 10^9,1\\leq w_i\\leq 10^4)$$$, denoting each request. It is guaranteed that $$$u_i$$$ is $$$v_i$$$\u0027s ancestor or $$$u_i\u003dv_i$$$.\u003c/p\u003e\u003cp\u003eIt is guaranteed that $$$\\sum n\\leq 10^6$$$ and $$$\\sum m\\leq 10^6$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each test case, print a single line containing an integer, denoting the maximum profits.\u003c/p\u003e"}},{"title":"Examples","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\u003e1\n5 3\n2 1 3 1 1\n2 5 2 3\n2 4 2 4\n1 2 3 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e13\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}