{"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\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$$$。提醒一下,一棵有$$$n$$$个节点的树是一个有$$$n-1$$$条边的连通图。\u003c/p\u003e\u003cp\u003e计算这棵树中具有以下性质的连通子图的数量:存在某种颜色(占多数的颜色),使得该子图中超过一半的节点都是这种颜色。\u003c/p\u003e\u003cp\u003e由于答案可能很大,输出对$$$998\\,244\\,353$$$取模后的结果。\u003c/p\u003e"}},{"title":"输入","value":{"format":"HTML","content":"\u003cp\u003e第一行包含一个整数$$$n$$$($$$1 \\le n \\le 3000$$$)— 树中节点的数量。\u003c/p\u003e\u003cp\u003e第二行包含$$$n$$$个整数$$$c_1\\ c_2\\ \\ldots\\ c_n$$$($$$1 \\le c_i \\le n$$$)— 节点的颜色。\u003c/p\u003e\u003cp\u003e接下来的$$$n-1$$$行中,第$$$i$$$行包含$$$2$$$个整数$$$u_i, v_i$$$($$$1 \\le u_i, v_i \\le n$$$,$$$u_i \\neq v_i$$$),表示树的边$$$(u_i, v_i)$$$。保证给定的图是一棵树。\u003c/p\u003e"}},{"title":"输出","value":{"format":"HTML","content":"\u003cp\u003e输出一个整数,即对$$$998\\,244\\,353$$$取模后的答案。\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\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"}},{"title":"示例 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"}},{"title":"注意","value":{"format":"HTML","content":"\u003cp\u003e在下面的图片中,我们用蓝色表示颜色$$$1$$$,红色表示颜色$$$2$$$,黄色表示颜色$$$3$$$。第一个示例如下所示:\u003c/p\u003e\u003cp\u003e\u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/a3fa5257edc36199fc53a4bc17090d7b?v\u003d1709224005\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e\u003c/p\u003e\u003cp\u003e该树共有$$$6$$$个非空连通子图:大小为$$$1$$$的$$$3$$$个,大小为$$$2$$$的$$$2$$$个,实际上后者就是整棵树。所有大小为$$$1$$$和$$$3$$$的子图都有占多数的颜色。对于大小为$$$2$$$的子图,只有由节点$$$1$$$和$$$2$$$组成的子图没有占多数的颜色(红色和黄色出现次数相同)。因此,有$$$6 - 1 \u003d 5$$$个具有占多数颜色的连通子图。\u003c/p\u003e\u003cp\u003e第二个示例如下所示,共有$$$8$$$个具有占多数颜色的连通子图:\u003c/p\u003e\u003cp\u003e\u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/237b040f87181f87205c4741d06c4924?v\u003d1709224005\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e\u003c/p\u003e"}}]}