luogu#P4923. [MtOI2018] gcd?人生赢家!
[MtOI2018] gcd?人生赢家!
Background
gcd is a person who loves games.
Problem Description
gcd has recently been playing an interesting game.
We abstract this game into a graph with nodes. gcd needs to find a total of treasures, which are distributed on the graph.
For each treasure, there is a prerequisite set . Only after obtaining all prerequisite treasures can this treasure be obtained.
gcd has a divine artifact. This artifact can teleport, and it can be used times. Each time, it can teleport to any node.
In this game, there are also extra achievements. These achievements reward a certain number of teleport uses. An achievement is completed at the instant when the set is satisfied.
Now gcd wants to know the fastest way to clear the game. Please find the minimum time needed to clear it.
Input Format
The input has a total of lines.
Line contains positive integers .
Line contains positive integer , the number of achievements.
In the next lines, each line starts with non-negative integer , meaning how many treasures are required, followed by integers, which are the IDs of the required treasures.
Line contains positive integers , meaning the reward counts of the achievements.
Line contains positive integers , meaning the positions of the treasures.
Line contains positive integer , the total number of edges.
In the next lines, each line contains positive integers , meaning there is an undirected edge between and with weight .
In the next lines, each line starts with non-negative integer , meaning the number of prerequisites for the treasure, followed by integers, which are the IDs of the required treasures.
The last line contains positive integer , the starting node.
Output Format
Output line with positive integer: the minimum time.
3 2 0
1
1 1
1
2 3
3
1 2 20
1 3 20
3 2 1
0
0
1
20
3 2 0
1
1 1
1
2 3
3
1 2 1
1 3 20
3 2 20
1 2
0
1
40
Hint
Subtasks
For of the testdata, .
For of the testdata, , , , , . The sum of all reward counts does not exceed . It is guaranteed that the positions of any two treasures are different. There may be multiple edges. It is guaranteed that a solution exists.
Source
Problem setter: b2019dy
78488
Translated by ChatGPT 5