#P9402. [POI 2020/2021 R3] Droga do domu

    ID: 10488 远端评测题 1000~2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>图论2020POI(波兰)图论建模最短路

[POI 2020/2021 R3] Droga do domu

Background

Translated from XXVIII Olimpiada Informatyczna - Stage III Droga do domu

d1t1。

Problem Description

There are nn vertices and mm edges, with no multiple edges or self-loops. Each edge has a length.

Vertex 11 is the school, and vertex nn is home.

There are ss 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 tt, with at most kk 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,tn,m,s,k,t.

The next mm lines each contain three integers a,b,ca,b,c, indicating an edge between aa and bb with length cc.

The next 2s2s lines describe the bus routes, with every two lines describing one route:

  • The first line contains three integers l,x,yl,x,y, meaning the route stops at ll vertices in total, the first bus departs at time xx, and the time interval between consecutive buses is yy.
  • The second line contains ll integers v1,,vlv_1,\dots,v_l, the ll 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, 2n100002\leq n\leq 100001m500001\leq m\leq 500001s250001\leq s\leq 250000k1000\leq k\leq 1000t1090\leq t\leq 10^91c1091\leq c\leq 10^92ln2\leq l\leq n0x1090\leq x\leq 10^91y1091\leq y\leq 10^91a,b,vn1\leq a,b,v\leq nl50000\sum l\leq 50000

Subtask ID Constraint Score
1 k=nk=n 20
2 vi<vi+1v_i<v_{i+1}
3 l=2l=2
4 t=0,x=0,y=1t=0,x=0,y=1
5

Translated by ChatGPT 5