{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eP. T. Tigris is a student currently studying graph theory. One day, when he was studying hard, GS appeared around the corner shyly and came up with a problem:\u003cbr\u003eGiven a graph with n nodes and m undirected weighted edges, every node having one of two colors, namely black (denoted as 0) and white (denoted as 1), you’re to maintain q operations of either kind:\u003cbr\u003e* Change x: Change the color of x\u003csup\u003eth\u003c/sup\u003e node. A black node should be changed into white one and vice versa.\u003cbr\u003e* Asksum A B: Find the sum of weight of those edges whose two end points are in color A and B respectively. A and B can be either 0 or 1.\u003cbr\u003eP. T. Tigris doesn’t know how to solve this problem, so he turns to you for help.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are several test cases.\u003cbr\u003eFor each test case, the first line contains two integers, n and m (1 ≤ n,m ≤ 10\u003csup\u003e5\u003c/sup\u003e), where n is the number of nodes and m is the number of edges.\u003cbr\u003eThe second line consists of n integers, the i\u003csup\u003eth\u003c/sup\u003e of which represents the color of the i\u003csup\u003eth\u003c/sup\u003e node: 0 for black and 1 for white.\u003cbr\u003eThe following m lines represent edges. Each line has three integer u, v and w, indicating there is an edge of weight w (1 ≤ w ≤ 2\u003csup\u003e31\u003c/sup\u003e - 1) between u and v (u !\u003d v).\u003cbr\u003eThe next line contains only one integer q (1 ≤ q ≤ 10\u003csup\u003e5\u003c/sup\u003e), the number of operations.\u003cbr\u003eEach of the following q lines describes an operation mentioned before.\u003cbr\u003eInput is terminated by EOF."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output several lines.\u003cbr\u003eThe first line contains “Case X:”, where X is the test case number (starting from 1).\u003cbr\u003eAnd then, for each “Asksum” query, output one line containing the desired answer."}},{"title":"Sample","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\u003e4 3\r\n0 0 0 0\r\n1 2 1\r\n2 3 2\r\n3 4 3\r\n4\r\nAsksum 0 0\r\nChange 2\r\nAsksum 0 0\r\nAsksum 0 1\r\n4 3\r\n0 1 0 0\r\n1 2 1\r\n2 3 2\r\n3 4 3\r\n4\r\nAsksum 0 0\r\nChange 3\r\nAsksum 0 0\r\nAsksum 0 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1:\r\n6\r\n3\r\n3\r\nCase 2:\r\n3\r\n0\r\n4\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}