QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓

#4211. 愛麗絲與鮑伯

统计

Alice 和 Bob 將輪流進行遊戲,由 Alice 先手。 他們擁有一個有向無環圖(DAG),其中每條邊 $u \to v$ 皆滿足 $u < v$。 此 DAG 中的所有頂點都被塗成兩種顏色之一,且頂點上放置有棋子(一個頂點可能包含多於一個棋子)。

在 Alice 的回合中,她會選擇一個包含至少一個棋子的白色頂點 $u$。接著,她會選擇一條從 $u$ 出發的邊 $u \to v$,並將一個棋子從頂點 $u$ 移動到頂點 $v$。 在 Bob 的回合中,他會選擇一個包含至少一個棋子的黑色頂點 $u$。接著,他會選擇一條從 $u$ 出發的邊 $u \to v$,並將一個棋子從頂點 $u$ 移動到頂點 $v$。 無法移動的人即為輸家。

Alice 和 Bob 尚未決定棋子的配置,但他們已決定遊戲開始時每個頂點最多包含一個棋子。在所有 $2^n$ 種棋子放置方式中,計算在雙方皆採取最佳策略的情況下,有多少種放置方式會讓 Alice 獲勝?由於此數值可能很大,請將結果對 $998\,244\,353$ 取模。

輸入格式

第一行包含兩個整數 $n, m$ ($1 \le n \le 300, 0 \le m \le \frac{n(n-1)}{2}$),分別代表圖中的頂點數與邊數。 第二行包含一個長度為 $n$ 的字串。若第 $i$ 個字元為 'W',則該頂點為白色;否則為 'B',代表黑色。 接下來的 $m$ 行,每行包含兩個頂點 $u, v$ ($1 \le u < v \le n$),代表一條邊 $u \to v$。 保證該 DAG 不會有重邊。

輸出格式

輸出一個整數:在每個頂點最多放置一個棋子的情況下,使得 Alice 獲勝的放置方式數量,對 $998\,244\,353$ 取模。

範例

輸入格式 1

5 4
WWWWW
1 2
2 3
3 4
4 5

輸出格式 1

30

說明

在第一個範例中,Alice 在所有她能至少移動一步的情況下都會獲勝(因為 Bob 永遠無法移動),因此答案為 $2^5 - 2$。

輸入格式 2

5 4
BWBWB
1 2
2 3
3 4
4 5

輸出格式 2

24

輸入格式 3

9 14
BWWBBBWWW
1 2
1 9
2 3
2 4
2 6
2 8
3 4
3 7
4 7
4 8
5 7
5 9
6 9
7 8

輸出格式 3

300

輸入格式 4

10 15
BWBWBBWWBW
1 2
1 5
1 10
2 6
2 8
3 6
3 7
4 10
5 6
5 7
5 8
6 8
6 9
7 10
8 9

輸出格式 4

228

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.