#435. Kart Race
Kart Race
Description
The annual kart race will soon be held in Byteland. The map of the race consists of different intersections and one-way streets. These intersections are labeled from to , the -th of which is located at . There are no cycles in the street network, one can only drive to some intersections with the strictly larger value of x-coordinate. The streets may only intersect at the intersections.
The race will start at the -st intersection and will finish at the -th intersection. The racers can pick their routes themselves, but they can only drive along the streets marked on the map. It is guaranteed that one can reach any place from , and any place can reach , so any route is valid.
The kart race attracts so many sponsors. Each intersection has a slot to set a banner, if you choose to set a banner at the -th intersection, the race company will get profits. You are a middleman in the race company, your job is to choose some intersections to set banners such that the total profits are maximized. You know that no racer is willing to see more than a banner, so for every possible route from to , you should guarantee that at most one intersection is chosen.
Format
Input
The first line contains a single integer (), the number of test cases. For each test case:
The first line of the input contains two integers and (, ), denoting the number of intersections and the number of one-way streets.
In the next lines, the -th line contains three integers , and (, ), describing the -th intersection. It is guaranteed that no two intersections share the same coordinator.
Each of the next lines contains two integers and (, ), denoting a one way street from to . It is guaranteed that each pair of and will be described at most once.
It is guaranteed that the sum of all is at most .
Output
For each test case, print a single integer in the first line, denoting the maximum total profits. Then print a sequence of integers in the second line, denoting the indexes of intersections you choose to set a banner. If there are multiple optimal solutions, you should print the lexicographically smallest one.
Samples
2
6 6
0 1 1
2 2 1
1 0 1
1 2 1
2 0 1
3 1 1
1 4
3 5
2 6
5 6
1 3
4 2
2 1
0 0 8
1 1 9
1 2
2
2 3
9
2