bzoj#P1139. [POI2009]Wie

[POI2009]Wie

题目描述

Byteasar has become a hexer - a conqueror of monsters. Currently he is to return to his hometown Byt eburg. 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 ofma king special swords that are very efficient against the beasts. The land Byteasar wanders throughis 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 practicalinfo rmation about the land (all hexers like to know these things). He knows what kind of monsters hemay come across each of the roads and how much time he needs to walk it down. He also knows in which vil lages there are blacksmiths and against what kinds of monsters the swords that they make work.Byteas ar wants to get back to Byteburg as soon as possible. As a hexer he is quite ashamed that he does no t know the best route, and that he has no sword on him at the moment. Help him find the shortest pat h to Byteburg such that whenever he could meet some king of monster, previously he would havea chanc e to get an appropriate sword to fight the beast. You need not worry about the number or weight of t he swords - every hexer is as strong as an ox, so he can carry (virtually) unlimited number of equip ment, swords in particular.

大陆上有 nn 个村庄,mm 条双向道路,pp 种怪物,kk 个铁匠,每个铁匠会居住在一个村庄里,你到了那个村庄后可以让他给你打造剑,每个铁匠打造的剑都可以对付一些特定种类的怪物,每条道路上都可能出现一些特定种类的怪物,每条道路都有一个通过所需要的时间。

现在要从 11 走到nn,初始的时候你没有剑,要求在经过一条道路的时候,对于任意一种可能出现在这条道路上的的怪物,你都有已经有至少一把剑可以对付他,求从 11 走到 nn 的最短时间(打造剑不需要时间)

输入格式

第一行正整数 n,m,p,kn,m,p,k (),分别表示点数,边数,剑/怪物的型号数,铁匠数。

接下来 kk 行描述铁匠,格式如下:所在点编号 ww,所能锻造的剑种类数 qq,升序给出 qq11pp 的不同的整数表示型号。

接下来 mm 行描述边:连接的顶点 x,yx,y,通过需要的时间 tt,路上的怪物数 ssss 个单调上升的 11pp 整数表示怪物型号。

输出格式

第一行输出最少时间。如果无法到达,输出 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

数据规模与约定

$1 \le n \le 200, 0 \le m \le 3000, 1 \le p \le 13, 0 \le k \le n$