luogu#P6512. [QkOI#R1] Quark and Flying Pigs
[QkOI#R1] Quark and Flying Pigs
Problem Description
You are given a simple, connected, undirected weighted graph with vertices and edges. At time , you are at vertex .
Suppose the current time is and you are at vertex . You may choose one of the following operations:
- Stay at vertex . After the operation, the time becomes .
- Choose an edge such that or . Then you move to the other endpoint of this edge. After the operation, the time becomes .
There are pieces of information. Each piece is of the form , meaning that at time , a flying pig with ID will appear at vertex . If you are at at that time, then you capture flying pig .
Now you need to find the maximum number of flying pigs you can capture.
Input Format
The first line contains three positive integers .
The next lines each contain three positive integers .
The next lines each contain two positive integers .
Output Format
Output one integer in a single line: the maximum number of flying pigs you can capture.
2 1 5
1 2 2
1 2
2 2
3 2
5 1
7 2
4
Hint
Sample Explanation
The optimal plan is as follows:
At time , choose to move to node , and the time becomes .
At time , capture the -nd flying pig, choose to stay at node , and the time becomes .
At time , capture the -rd flying pig, choose to move to node , and the time becomes .
At time , capture the -th flying pig, choose to move to node , and the time becomes .
At time , capture the -th flying pig.
Constraints
For of the testdata, .
For of the testdata, , , , , , .
Translated by ChatGPT 5