#P2446. [SDOI2010] 大陆争霸
[SDOI2010] 大陆争霸
Description
On Fantasia Year May late at night, Spring · Blazer delivered an oracle: “Trust me, earn eternal life.” The morale of the Chris legions soared. As the commander-in-chief of the Chris legions, you decide to seize this opportunity to launch a surprise attack and defeat Jason in one stroke. Specifically, Jason has cities connected by directed roads. Shenyu Town is city , and Jason’s capital is city . You only need to destroy the Great Temple of Zeng · Blazer located in the capital of Jason; once it falls, Jason’s faith, army, and everything else will collapse and vanish.
To minimize your own losses, you decide to use self-destruct robots to accomplish this task. The only difficulty is that some cities in Jason are protected by barriers. You cannot enter a city without first disabling its barrier. Each city’s barrier is maintained by several barrier generators distributed in other cities. If you want to enter a city, you must destroy all the barrier generators that maintain that city’s barrier.
You have an unlimited number of self-destruct robots. Once a robot enters a city, it can detonate instantly to destroy a single target (either a barrier generator or the Great Temple), and of course the robot itself is also destroyed. You need to find the minimum time required to bring down Jason.
It is guaranteed that there is always a solution. No barrier generator that maintains a city’s barrier is located inside that very city. There may be multiple roads between the same pair of cities, and self-loops may exist.
Input Format
The first line contains two positive integers .
The next lines each contain three positive integers , indicating there is a directed road from city to city , and a self-destruct robot needs time to traverse this road.
Then follow lines, each describing one city. Each line starts with a positive integer , the number of barrier generators maintaining this city’s barrier, followed by city indices between indicating the locations of those generators. If , then this city has no barrier. It is guaranteed that .
Output Format
Output a single positive integer: the minimum time required to defeat Jason.
6 6
1 2 1
1 4 3
2 3 1
2 5 2
4 6 2
5 3 2
0
0
0
1 5
0
2 3 5
5
Hint


Constraints:
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号