Colorful Star

AtCoder
IDarc176_f
Time2000ms
Memory256MB
Difficulty
There is a tree with $NM+1$ vertices numbered $0$ to $NM$. The $i$\-th edge ($1 \le i \le NM$) connects vertices $i$ and $\max(i-N,0)$. Initially, vertex $i$ is colored with color $i \bmod N$. You can perform the following operation zero or more times: * Choose two vertices $u$ and $v$ connected by an edge. Repaint the color of vertex $u$ with that of vertex $v$. Find the number, modulo $998244353$, of possible trees after the operations. Two trees are distinguished if and only if some vertex has different colors. ## Constraints * $1 \le N, M \le 2 \times 10^5$ ## Input The input is given from Standard Input in the following format: $N$ $M$ [samples]
Samples
Input #1
3 1
Output #1
42

One possible sequence of operations is as follows. Including this one, there are $42$ possible final trees.
![image](https://img.atcoder.jp/arc176/star.png)
Input #2
4 2
Output #2
219100
Input #3
20 24
Output #3
984288778
Input #4
123456 112233
Output #4
764098676
API Response (JSON)
{
  "problem": {
    "name": "Colorful Star",
    "description": {
      "content": "There is a tree with $NM+1$ vertices numbered $0$ to $NM$. The $i$\\-th edge ($1 \\le i \\le NM$) connects vertices $i$ and $\\max(i-N,0)$. Initially, vertex $i$ is colored with color $i \\bmod N$. You can",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc176_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a tree with $NM+1$ vertices numbered $0$ to $NM$. The $i$\\-th edge ($1 \\le i \\le NM$) connects vertices $i$ and $\\max(i-N,0)$.\nInitially, vertex $i$ is colored with color $i \\bmod N$. You can...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments