{"trustable":false,"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\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 type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e给定一个 $$$n$$$ 个节点的树,节点 $$$i$$$ 的颜色是 $$$c_i$$$ 。\u003c/p\u003e\n\u003cp\u003e请计算这个树存在多少不同的连通子图,满足这个连通子图中,存在某种颜色,其出现次数 \u003cspan class\u003d\"tex-font-style-bf\"\u003e严格大于\u003c/span\u003e 连通子图中节点数量的一半。\u003c/p\u003e\n\u003cp\u003e答案可能很大,请对 $$$998\\,244\\,353$$$ 取模。\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of input contains one integer $$$n$$$ ($$$1 \\le n \\le 3000$$$)\u0026nbsp;— the number of nodes in the tree.\u003c/p\u003e\n\u003cp\u003eThe second line contains $$$n$$$ integers $$$c_1\\ c_2\\ \\ldots\\ c_n$$$ ($$$1 \\le c_i \\le n$$$)\u0026nbsp;— the colors of the nodes.\u003c/p\u003e\n\u003cp\u003eThe $$$i$$$-th of next $$$n-1$$$ lines contains $$$2$$$ integers $$$u_i, v_i$$$ ($$$1 \\le u_i, v_i \\le n$$$, $$$u_i \\neq v_i$$$), representing the edge $$$(u_i, v_i)$$$ of the tree. It is guaranteed that the given graph is a tree.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint a single integer\u0026nbsp;— answer to the problem modulo $$$998\\,244\\,353$$$.\u003c/p\u003e"}},{"title":"Sample 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\u003e3\n2 3 3\n1 2\n2 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Sample 2","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\n1 1 3 3\n1 2\n1 3\n1 4\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e8\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the following pictures, we use blue for color $$$1$$$, red for color $$$2$$$, and yellow for color $$$3$$$. The first example looks as follows:\u003c/p\u003e\n\u003cp\u003e\u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/a3fa5257edc36199fc53a4bc17090d7b?v\u003d1691997729\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e\u003c/p\u003e\n\u003cp\u003eThe tree has a total of $$$6$$$ non-empty connected subgraphs:\u0026nbsp;$$$3$$$ of size $$$1$$$, $$$2$$$ of size $$$2$$$ and $$$1$$$ of size $$$3$$$, the latter in fact being the whole tree. All such subgraphs of sizes $$$1$$$ and $$$3$$$ have a majority color. For those of size $$$2$$$ only the subgraph induced by vertices $$$1$$$ and $$$2$$$ does not have a majority color (red and yellow both appear equally often in it). Therefore, there are $$$6 - 1 \u003d 5$$$ connected subgraphs with a majority color.\u003c/p\u003e\n\u003cp\u003eThe second example looks as follows, and it has $$$8$$$ connected subgraphs with a majority color:\u003c/p\u003e\n\u003cp\u003e\u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/237b040f87181f87205c4741d06c4924?v\u003d1691997729\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e\u003c/p\u003e"}}]}