{"problem":{"name":"Red and Blue Tree","description":{"content":"Given are a tree with $N$ vertices, a sequence of $M$ numbers $A=(A_1,\\ldots,A_M)$, and an integer $K$.   The vertices are numbered $1$ through $N$, and the $i$\\-th edge connects Vertices $U_i$ and $V","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc222_e"},"statements":[{"statement_type":"Markdown","content":"Given are a tree with $N$ vertices, a sequence of $M$ numbers $A=(A_1,\\ldots,A_M)$, and an integer $K$.  \nThe vertices are numbered $1$ through $N$, and the $i$\\-th edge connects Vertices $U_i$ and $V_i$.\nWe will paint each of the $N-1$ edges of this tree red or blue. Among the $2^{N-1}$ such ways, find the number of ones that satisfies the following condition, modulo $998244353$.\nCondition:  \nLet us put a piece on Vertex $A_1$, and for each $i=1,\\ldots,M-1$ in this order, move it from Vertex $A_i$ to Vertex $A_{i+1}$ along the edges in the shortest path. After all of these movements, $R-B=K$ holds, where $R$ and $B$ are the numbers of times the piece traverses a red edge and a blue edge, respectively.\n\n## Constraints\n\n*   $2 \\leq N \\leq 1000$\n*   $2 \\leq M \\leq 100$\n*   $|K| \\leq 10^5$\n*   $1 \\leq A_i \\leq N$\n*   $1\\leq U_i,V_i\\leq N$\n*   The given graph is a tree.\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $M$ $K$\n$A_1$ $A_2$ $\\ldots$ $A_M$\n$U_1$ $V_1$\n$\\vdots$\n$U_{N-1}$ $V_{N-1}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc222_e","tags":[],"sample_group":[["4 5 0\n2 3 2 1 4\n1 2\n2 3\n3 4","2\n\nIf we paint the $1$\\-st and $3$\\-rd edges red and the $2$\\-nd edge blue, the piece will traverse the following numbers of red and blue edges:\n\n*   $0$ red edges and $1$ blue edge when moving from Vertex $2$ to $3$,\n*   $0$ red edges and $1$ blue edge when moving from Vertex $3$ to $2$,\n*   $1$ red edge and $0$ blue edges when moving from Vertex $2$ to $1$,\n*   $2$ red edges and $1$ blue edge when moving from Vertex $1$ to $4$,\n\nfor a total of $3$ red edges and $3$ blue edges, satisfying the condition.\n![image](https://img.atcoder.jp/ghi/f9b2b199fb6eedaca02e15ff556b72b1.png)\nAnother way to satisfy the condition is to paint the $1$\\-st and $3$\\-rd edges blue and the $2$\\-nd edge red. There is no other way to satisfy it, so the answer is $2$."],["3 10 10000\n1 2 1 2 1 2 2 1 1 2\n1 2\n1 3","0\n\nThere may be no way to paint the tree to satisfy the condition."],["10 2 -1\n1 10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10","126"],["5 8 -1\n1 4 1 4 2 1 3 5\n1 2\n4 1\n3 1\n1 5","2"]],"created_at":"2026-03-03 11:01:13"}}