QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#4211. アリスとボブ

Statistics

アリスとボブは、アリスを先攻として交互にゲームを行います。 彼らは、各辺 $u \to v$ が $u < v$ を満たすような有向非巡回グラフ(DAG)を持っています。 このDAGのすべての頂点は2色のいずれかに塗られており、頂点にはトークンが置かれています(1つの頂点に複数のトークンが置かれている場合もあります)。

アリスの番では、アリスは少なくとも1つのトークンを持つ白い頂点 $u$ を選びます。次に、その頂点から出る辺 $u \to v$ を選び、頂点 $u$ から頂点 $v$ へトークンを1つ移動させます。 ボブの番では、ボブは少なくとも1つのトークンを持つ黒い頂点 $u$ を選びます。次に、その頂点から出る辺 $u \to v$ を選び、頂点 $u$ から頂点 $v$ へトークンを1つ移動させます。 動かすことができなくなったプレイヤーが負けとなります。

アリスとボブはまだトークンの配置を決めていませんが、ゲーム開始時に各頂点には最大で1つのトークンしか置かないことにしました。すべての $2^n$ 通りのトークンの配置のうち、両者が最適にプレイしたときにアリスが勝つ配置は何通りあるでしょうか。この値は大きくなる可能性があるため、$998\,244\,353$ で割った余りを求めてください。

入力

1行目には、グラフの頂点数と辺数を表す2つの整数 $n, m$ ($1 \le n \le 300, 0 \le m \le \frac{n(n-1)}{2}$) が与えられます。 2行目には、長さ $n$ の文字列が与えられます。$i$ 番目の文字が 'W' ならばその頂点は白であり、そうでなければ 'B' であり黒です。 続く $m$ 行の各行には、辺 $u \to v$ を表す2つの頂点 $u, v$ ($1 \le u < v \le n$) が与えられます。 このDAGには多重辺がないことが保証されています。

出力

各頂点に最大1つのトークンを置く配置のうち、アリスが勝つような配置の数を $998\,244\,353$ で割った余りを出力してください。

入出力例

入力 1

5 4
WWWWW
1 2
2 3
3 4
4 5

出力 1

30

注記

最初の例では、アリスが少なくとも1回動かせる(ボブは一度も動かせないため)すべての場合においてアリスが勝つため、答えは $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.