SP10586 PROBMOR - Problems in Moria

Description

Balin, in his last days, needed to put more workers on the tunnels of Moria to build a lot of shelters to his people and to discovery the depths of that land. However, he didn't know where to put a collection point in order to take all the rocks in the way and bring all of them outside of Moria. The only thing he knew was this collection point needed to be fix in a junction point that connects two independent parts. If there's no point with this feature, any junction point, that's not the source one, can be used.

Input Format

The input contains several test cases. Each test is given by a line with two integers X 0 X number of tunnels. Then, the next Y lines are followed by three integers: A 0 AB 0Bcapacity C of workers that can walk through there. After that, there's a line with only one integer which is the start point, in the other words, the point where the workers are divided.

Output Format

For each test case, display it's case number followed by a blank line. In the next line display the number Z of points that can be used as a collection point and, in the next Z lines shows in decreasing order the maximum number of workers that can be used. Each test case is separated by a blank line as the sample output.