#P3489. [POI 2009] WIE-Hexer

    ID: 2559 Type: RemoteJudge 1000ms 125MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>动态规划,dp2009POI最短路

[POI 2009] WIE-Hexer

题目描述

Byteasar has become a hexer - a conqueror of monsters.

Currently he is to return to his hometown Byteburg. The way home, alas, leads through a land full of beasts. Fortunately the habitants, forced to fight the monsters for centuries, have mastered the art of blacksmithery - they are now capable of making special swords that are very efficient against the beasts.

The land Byteasar wanders through is quite vast: many towns lie there, and many roads connect them.

These roads do not cross outside the towns (mostly because some of them are underground passages).

Byteasar has gathered all practical information about the land (all hexers like to know these things).

He knows what kind of monsters he may come across each of the roads and how much time he needs to walk it down.

He also knows in which villages there are blacksmiths and against what kinds of monsters the swords that they make work.

Byteasar wants to get back to Byteburg as soon as possible.

As a hexer he is quite ashamed that he does not know the best route, and that he has no sword on him at the moment.

Help him find the shortest path to Byteburg such that whenever he could meet some king of monster, previously he would have a chance to get an appropriate sword to fight the beast.

You need not worry about the number or weight of the swords - every hexer is as strong as an ox, so he can carry (virtually) unlimited number of equipment, swords in particular.

输入格式

The first line of the standard input holds four integers: n,m,p,kn,m,p,k ($1\le n\le 200,0\le m\le 3000,1\le p\le 13,0\le k\le n$),separated by single spaces, that denote respectively:

the number of towns, the number of roads connecting them,the number of different kinds of monsters and the number of blacksmiths.

The towns are numbered from 11 to nn in such a way that nn is Byteburg's number and 11 is the number of the village which Byteasar starts in. The monster kinds are numbered from 11 to pp.

In the following kk lines the profiles of successive blacksmiths are given,one per line. The (i+1)(i+1)-st line holds the integers wi,qi,ri,1<ri,2<...<ri,qiw_i,q_i,r_{i,1}<r_{i,2}<...<r_{i,q_i}(1win,1qip,1ri,jp1\le w_i\le n,1\le q_i\le p,1\le r_{i,j}\le p),separated by single spaces, that denote respectively: the number of town in which the blacksmith lives, the number of different kinds of monsters against which his swords are efficient, and the kinds of monsters themselves (in increasing order). Note that a town may have more than one blacksmith.

Then mm lines with roads' descriptions follow.The (k+i+1)(k+i+1)-th line holds the integersvi,wi,ti,si,ui,1<ui,2<...<ui,siv_i,w_i,t_i,s_i,u_{i,1}<u_{i,2}<...<u_{i,s_i}($1\le v_i<w_i\le n,1\le t_i\le 500,0\le s_i\le p,1\le u_{i,j}\le p$)separated by single spaces, that denote respectively: the towns that the road connects, the time needed to walk down the road (same in both directions), the number of different kinds of monsters that may appear on that road, and finally the kinds of monsters themselves (in increasing order). No two roads connect the same pair of towns.

输出格式

Your programme is to print out one integer to the standard output - the minimum summary time required to reach Byteburg.

Should reaching Byteburg be impossible, the number should be 1-1.

6 7 4 2
2 1 2
3 2 1 3
1 2 2 0
2 3 9 0
1 4 2 1 2
2 5 3 0
4 5 5 2 2 3
4 6 18 0
5 6 3 2 1 2

24