#P9402. [POI 2020/2021 R3] Droga do domu
[POI 2020/2021 R3] Droga do domu
Background
Translated from XXVIII Olimpiada Informatyczna - Stage III Droga do domu。
d1t1。
Problem Description
There are vertices and edges, with no multiple edges or self-loops. Each edge has a length.
Vertex is the school, and vertex is home.
There are 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 , with at most 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 .
The next lines each contain three integers , indicating an edge between and with length .
The next lines describe the bus routes, with every two lines describing one route:
- The first line contains three integers , meaning the route stops at vertices in total, the first bus departs at time , and the time interval between consecutive buses is .
- The second line contains integers , the 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.
4 4 2 1 1
1 2 2
2 3 4
1 3 3
4 3 2
4 0 10
1 2 3 4
3 2 7
1 3 2
8
10 45 17 10 123
1 2 1
1 3 100
1 4 100
1 5 100
1 6 100
1 7 100
1 8 100
1 9 100
1 10 100
2 3 1
2 4 100
2 5 100
2 6 100
2 7 100
2 8 100
2 9 100
2 10 100
3 4 1
3 5 100
3 6 100
3 7 100
3 8 100
3 9 100
3 10 100
4 5 1
4 6 100
4 7 100
4 8 100
4 9 100
4 10 100
5 6 1
5 7 100
5 8 100
5 9 100
5 10 100
6 7 1
6 8 100
6 9 100
6 10 100
7 8 1
7 9 100
7 10 100
8 9 1
8 10 100
9 10 1
2 0 1
1 2
2 0 1
1 3
2 0 1
2 3
2 0 1
2 4
2 0 1
3 4
2 0 1
3 5
2 0 1
4 5
2 0 1
4 6
2 0 1
5 6
2 0 1
5 7
2 0 1
6 7
2 0 1
6 8
2 0 1
7 8
2 0 1
7 9
2 0 1
8 9
2 0 1
8 10
2 0 1
9 10
132
见附件
1000000102
见附件
11100000071
Hint
Sample explanation: 
For all testdata, ,,,,,,,,,,。
| Subtask ID | Constraint | Score |
|---|---|---|
| 1 | 20 | |
| 2 | ||
| 3 | ||
| 4 | ||
| 5 |
Translated by ChatGPT 5