QOJ.ac

QOJ

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

#3242. Dice Travel

统计

Before the band f goes on tour, it is customary to organize a dice trip for the band members to relax. A dice trip consists of $N$ locations, labeled $1, 2, \cdots, N$. The band members agree to meet at $s_0$; the dice trip officially begins when everyone arrives at the meeting point $s_0$ on the day of the trip.

A major joy of the dice trip is that the next destination is determined by a die. Of course, this die does not necessarily have six sides. We can assume that if the band members are currently at location $i$, the next destination is generated with equal probability from $m_i$ distinct candidate locations, which are $l_{i, 1}, l_{i, 2}, \cdots, l_{i, m_i}$. Let $s_t$ be the result of the $t$-th roll; then the $(t+1)$-th move will be to the location determined by rolling the die at $s_t$. The first roll takes place at the starting point $s_0$. Since the band needs to rehearse for the tour later, it is agreed that regardless of which locations are visited, the dice trip must end after the $T$-th roll, upon arriving at $s_T$.

Enjoying the sights at $s_0, s_1, \cdots, s_T$ is also a great pleasure of the dice trip. Regardless of whether they have been there before, every time the band members arrive at a location $s_t$, they enjoy the scenery and food. However, if they have visited $s_t$ before, the keyboardist S, who is responsible for rolling the dice, will definitely say before rolling the $(t+1)$-th die: "It feels like the last time we were at $s_t$ was at time $t'$, and last time we rolled $s_{t'+1}$ here. I wonder what the result will be this time." The drummer Y is particularly fond of nonsense jokes, so every time S says this, he records $s_{t'+1}$. Specifically, if $s_T$ is a location that has been visited before, S will say: "It feels like the last time we were at $s_t$ was at time $t'$, and last time we rolled $s_{t'+1}$ here, but we won't roll this time because the dice trip ends here." Of course, Y will also record this $s_{t'+1}$.

As a summary of this dice trip, Y adds up all the recorded $s_{t'+1}$ values, which is defined as S's "nonsense index."

The next tour of f is about to begin, so S is planning to take everyone on a dice trip again. Hearing that you are a fan of f, S has found you and hopes you can help him calculate the expected value of his nonsense index for this dice trip.

Input

The input is read from standard input.

The first line contains three positive integers $N, s_0, T$, representing the number of possible locations, the starting point of the dice trip, and the number of dice rolls in the trip, respectively.

The next $N$ lines, the $i$-th line ($1\le i\le N$), first input a positive integer $m_i$, representing the number of candidate locations for the next destination from location $i$; then input $m_i$ positive integers, representing these $m_i$ locations $l_{i, 1}, l_{i, 2}, \cdots, l_{i, m_i}$. It is guaranteed that for any $i$, the $m_i$ input locations are distinct.

Output

Output to standard output.

Output a single number representing the expected value of the nonsense index. Suppose the expected value of the nonsense index, when expressed as an irreducible fraction $p/q$ (where $p$ and $q$ are coprime), is $x$ such that $qx\equiv p \pmod{998,244,353}$ and $0\le x< 998,244,353$. It can be proven that under the given constraints, $x$ exists and is unique.

Examples

Input 1

5 1 2
3 2 3 4
2 1 5
2 1 5
2 1 5
3 2 3 4

Output 1

499122178

Note

The scenarios contributing to the answer are: starting from point $1$, moving to any of the points $2, 3, 4$, and returning to point $1$. For a point $i (i=2, 3, 4)$, the probability of moving to point $i$ and returning to point $1$ is $1/6$, and the contribution is $i$, so the expectation is $\frac{1}{6}\times (2+3+4) = \frac{3}{2}$.

Since $499122178 \times 2 = 998244356 \equiv 3 \pmod {998244353}$, $3/2$ modulo $998,244,353$ is $499,122,178$, so the correct output is $499,122,178$.

Input 2

7 1 4
6 2 3 4 5 6 7
6 1 3 4 5 6 7
6 1 2 4 5 6 7
6 1 2 3 5 6 7
6 1 2 3 4 6 7
6 1 2 3 4 5 7
6 1 2 3 4 5 6

Output 2

274979351

Note

The answer before conversion is $1625/432\approx 3.761574$, and $432\times 274979351 = 118791079632 \equiv 1625 \pmod{998244353}$, so the answer modulo $998,244,353$ is $274979351$.

Input 3

3.in

Output 3

3.ans

Subtasks

For $100\%$ of the data, it is guaranteed that $1\le N\le 100$, $1\le T\le 100$, $1\le s_0\le N$, $1\le m_i\le N$, $\sum_{i=1}^N m_i\le 5000$, $1\le l_{i, j}\le N$, and $\forall 1\le i\le N, \forall 1\le j_1< j_2\le m_i, l_{i, j_1}\ne l_{i, j_2}$.

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.