P9402 [POI 2020/2021 R3] Road Home
Background
Translated from [XXVIII Olimpiada Informatyczna - Stage III](https://sio2.mimuw.edu.pl/c/oi28-3/dashboard/) [Droga do domu](https://szkopul.edu.pl/problemset/problem/ZfS_tobZ_7xdR6D5s6Tegur3/statement/)。
d1t1。
Description
There are $n$ vertices and $m$ edges, with no multiple edges or self-loops. Each edge has a length.
Vertex $1$ is the school, and vertex $n$ is home.
There are $s$ bus routes. A bus stops at every vertex on its route, and it will not stop at the same vertex twice. The travel time along an edge equals its length. For each route, the departure time of the first bus and the departure interval are given.
Starting from the school at time $t$, with at most $k$ transfers, find the earliest time you can arrive home.
Only travel time and waiting time are counted. Transfer time is not counted.
Input Format
The first line contains five integers $n,m,s,k,t$.
The next $m$ lines each contain three integers $a,b,c$, indicating an edge between $a$ and $b$ with length $c$.
The next $2s$ lines describe the bus routes, with every two lines describing one route:
- The first line contains three integers $l,x,y$, meaning the route stops at $l$ vertices in total, the first bus departs at time $x$, and the time interval between consecutive buses is $y$.
- The second line contains $l$ integers $v_1,\dots,v_l$, the $l$ vertices the route stops at, in order.
Output Format
Output one integer in one line: the answer.
If it is impossible to get home, output one line containing the string `NIE`.
Explanation/Hint
Sample explanation: 
For all testdata, $2\leq n\leq 10000$,$1\leq m\leq 50000$,$1\leq s\leq 25000$,$0\leq k\leq 100$,$0\leq t\leq 10^9$,$1\leq c\leq 10^9$,$2\leq l\leq n$,$0\leq x\leq 10^9$,$1\leq y\leq 10^9$,$1\leq a,b,v\leq n$,$\sum l\leq 50000$。
| Subtask ID | Constraint | Score |
| :----------: | :----------: | :----------: |
| 1 | $k=n$ | 20 |
| 2 | $v_i