Universal Cup Judging System

Universal Cup

시간 제한: 2.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓
통계

求滿足以下所有條件、包含 $N$ 個標號為 $1, 2, \dots, N$ 的頂點的二元樹(二元樹是一種有根樹,其中每個頂點至多有一個左子節點與至多一個右子節點)的數量,並將結果對 $998244353$ 取模後輸出。

  • 對於每個 $i = 1, 2, \dots, N$,頂點 $i$ 的前序走訪編號為 $i$。特別地,頂點 $1$ 是根節點。
  • 對於每個 $i = 1, 2, \dots, M$,頂點 $A_i$ 的中序走訪編號為 $B_i$。

若存在一個頂點 $v$ 滿足以下至少一項條件,則視為兩棵二元樹不同:

  • $v$ 的左子節點的存在性或頂點編號不同。
  • $v$ 的右子節點的存在性或頂點編號不同。

二元樹中每個頂點 $v$ 的前序走訪編號與中序走訪編號,分別定義為執行以下虛擬碼中的 dfs(root) 時,記錄於 preorder[v] 與 inorder[v] 中的值:

pre_cnt = 1; in_cnt = 1
def dfs(v):
    preorder[v] = pre_cnt; pre_cnt += 1
    if v has a left child:
        dfs(left child of v)
    inorder[v] = in_cnt; in_cnt += 1
    if v has a right child:
        dfs(right child of v)

輸入格式

輸入以以下格式給出:

$$\begin{aligned} &N \ M \\ &A_1 \ B_1 \\ &A_2 \ B_2 \\ &\vdots \\ &A_M \ B_M \end{aligned}$$

  • 所有輸入值皆為整數。
  • $1 \le M \le N \le 500$
  • $1 \le A_i, B_i \le N$
  • $A_i \ne A_j$($i \ne j$)
  • $B_i \ne B_j$($i \ne j$)

輸出格式

在單獨一行輸出答案。

範例

輸入格式 1

3 1
2 1

輸出格式 1

2

輸入格式 2

5 3
1 3
2 5
4 2

輸出格式 2

0

輸入格式 3

30 6
12 26
9 5
15 14
19 15
4 2
10 4

輸出格式 3

550222816

說明

在第一個範例中,恰好有兩棵二元樹滿足條件。其中一棵以頂點 $1$ 為根,頂點 $2$ 為頂點 $1$ 的左子節點,頂點 $3$ 為頂點 $2$ 的右子節點。另一棵以頂點 $1$ 為根,頂點 $2$ 為頂點 $1$ 的左子節點,頂點 $3$ 為頂點 $1$ 的右子節點。它們的前序與中序走訪編號皆符合給定的限制。

在第二個範例中,沒有任何二元樹滿足條件。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1406EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.