{"problem":{"name":"Inversion of Tree","description":{"content":"You are given a permutation $P=(P_1,P_2,\\ldots,P_N)$ of $(1,2,\\ldots,N)$. For each $K=0,1,\\ldots,N-1$, find the number, modulo $998244353$, of trees with $N$ vertices numbered $1$ to $N$ that satisfy ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":4000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc323_g"},"statements":[{"statement_type":"Markdown","content":"You are given a permutation $P=(P_1,P_2,\\ldots,P_N)$ of $(1,2,\\ldots,N)$.\nFor each $K=0,1,\\ldots,N-1$, find the number, modulo $998244353$, of trees with $N$ vertices numbered $1$ to $N$ that satisfy the following condition.\n\n*   Among the pairs of vertices $(u_i,v_i)\\ (u_i < v_i)$ that are directly connected by an edge in the tree, exactly $K$ pairs satisfy $P_{u_i}>P_{v_i}$.\n\n## Constraints\n\n*   $2\\leq N\\leq 500$\n*   $P$ is a permutation of $(1,2,\\ldots,N)$.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$ \n$P_1$ $P_2$ $\\ldots$ $P_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc323_g","tags":[],"sample_group":[["3\n1 3 2","1 2 0\n\nThe answer for $K=0$ is $1$: the tree with edges connecting vertices $1,2$ and $1,3$. Indeed, $P_1 < P_2$ and $P_1<P_3$.\nThe answer for $K=1$ is $2$: the tree with edges connecting vertices $1,2$ and $2,3$, and another with edges connecting vertices $1,3$ and $2,3$. Indeed, in the tree with edges connecting vertices $1,2$ and $2,3$, we have $P_1 < P_2$, $P_2>P_3$."],["10\n3 1 4 10 8 6 9 2 7 5","294448 2989776 12112684 25422152 30002820 20184912 7484084 1397576 108908 2640"]],"created_at":"2026-03-03 11:01:14"}}