P18162 [NWERC 2026] Karlsruhe Commute
Description
After a long day at work, you are travelling home using the Karlsruhe *Stadtbahn*, a network of tram-train lines connecting the different parts of the city and the surrounding countryside. Being very sleepy, you immediately fall asleep when embarking on a carriage. You wake up every $k$ stops, giving you the opportunity to switch to any train line that stops at the same station, in either direction. If you stay on your current train, you fall asleep again after the train leaves that station. After a train has reached one of the two terminating stations of a train line, it immediately reverses and starts going the other direction. After you exit a train, you stay awake until you enter the next train.
Given the map of the Karlsruhe *Stadtbahn*, determine whether you can get from work (station $1$) to your home (station $n$) while being this sleepy. Note that you must be awake at station $n$ to exit the train there.
Input Format
The input consists of the following.
- One line with three integers $n$, $m$, and $k$ ($2 \leq n \leq 10^5$, $1 \leq m \leq 10\,000$, $1 \leq k \leq 1000$), the number of train stations, the number of train lines, and how often you wake up.
- $m$ lines (one for each train line), each with an integer $s$ ($2 \leq s \leq n$), the number of stations where this line stops, followed by $s$ pairwise distinct integers $v_1, \dots, v_s$ ($1 \leq v_j \leq n$ for each $j$), the stations on that line, in order.
The total number of stops across all lines is at most $5 \cdot 10^5$.
The train network is not necessarily connected.
Output Format
If it is possible to reach station $n$ from station $1$ even though you are sleepy, output `possible`. Otherwise, output `impossible`.
Explanation/Hint
### Sample 1 Explanation
You can never reach the second train line, because you only ever wake up at stations $1$, $4$, and $7$.
### Sample 2 Explanation
You can eventually reach any station on any line. To get home, you take the first line and wake up at station $4$, and then wake up at station $5$ after the train reverses its direction. There, you can switch to line $2$ in the direction of your home, fall asleep, and wake up at station $10$, arriving at home.
### Sample 3 Explanation
You wake up at every stop on the first line, but because there is no connection from the first line to the third line, you can never arrive home.
### Sample 4 Explanation
You can switch to the third line at station $3$ and then to the second line at station $13$ to arrive home. You can never reach the fourth line. Only stations $1$, $3$, $5$, $11$, $13$, and $15$ are reachable, while the other nine stations are not.