| NUS CS3233 Final Team Contest 2024 |
|---|
| Finished |
Alice and Bob will play in a directed graph $$$H$$$. The $$$i$$$-th vertex in $$$H$$$ initially has a value $$$Y_i$$$. The game will proceed as follows.
If $$$H$$$ contains a cycle, then the game is a tie.
Otherwise, Alice and Bob will take turns to choose a vertex in $$$H$$$ to start a chain. Alice starts first. Each player will do all of the following in their turn:
The player who cannot make a move loses the game.
Note that, because a player can change the value of a vertex to an arbitrarily large value, the number of moves in a game might be unbounded; i.e., "infinite". However, it turns out that the game will eventually always end; i.e., "finite". We shall leave this philosophical question of the "finite" and "infinite" nature of the game to the reader.
We want to find out if Bob can win the game, assuming both players play optimally.
There's a twist: the author of this problem is too lazy to generate strong test cases, so the graph $$$H$$$ and initial values $$$Y_i$$$ are generated randomly, according to the following rules.
You are given a simple undirected graph $$$G = (V, E)$$$ (with no self-loops, and the graph is not necessarily connected) with $$$N$$$ vertices and $$$M$$$ edges. The vertices are numbered from $$$1$$$ to $$$N$$$, where vertex $$$i$$$ has a value $$$X_i$$$. Each edge $$$j$$$ also has a value $$$A_j$$$, $$$B_j$$$, and $$$C_j$$$.
Create the directed graph $$$H$$$ and values $$$Y_i$$$ as follows:
Now, the problem becomes: given the graph $$$G$$$ and the values $$$X_i$$$, $$$A_i$$$, $$$B_i$$$, and $$$C_i$$$, find the probability that Bob wins the game, modulo $$$998\,244\,353$$$. It can be proven that the probability that Bob wins the game can be represented as an irreducible fraction $$$\frac{P}{Q}$$$, where $$$P$$$ and $$$Q$$$ are integers, and $$$Q$$$ is coprime to $$$998\,244\,353$$$. You need to output the value of $$$P \cdot Q^{-1} \bmod 998\,244\,353$$$.
The first line of input contains two integers $$$N$$$ $$$(1 \leq N \leq 12)$$$ and $$$M$$$ $$$(0 \leq M \leq \frac{N(N-1)}{2})$$$, the number of vertices and edges in the graph $$$G$$$.
The next line contains $$$N$$$ integers $$$X_1, X_2, \ldots, X_N$$$ $$$(0 \leq X_i \lt 998\,244\,353 - 1)$$$, the values of the vertices in $$$G$$$.
The next $$$M$$$ lines each contain five integers $$$u_i$$$, $$$v_i$$$, $$$A_i$$$, $$$B_i$$$, and $$$C_i$$$ $$$(1 \leq u_i, v_i \leq N$$$, $$$0 \leq A_i, B_i, C_i \lt 998\,244\,353$$$, $$$1 \leq A_i + B_i + C_i \lt 998\,244\,353)$$$, representing an edge $$$(u_i,v_i)$$$ in $$$G$$$.
Output a single integer, the probability that Bob wins the game, modulo $$$998\,244\,353$$$.
3 0 1 2 3
748683265
4 6 1 2 3 4 1 3 42 42 42 1 4 3 3 3 1 2 2 2 2 3 4 3 3 3 2 4 3 3 3 2 3 42 42 42
597577278
In the first sample, there are $$$24$$$ possible games $$$(H, Y)$$$ generated. The probability that Bob wins the game is $$$\frac{1}{4} \equiv 748\,683\,265 \pmod{998\,244\,353}$$$.
| Name |
|---|


