Broppers -------- On the planet of Pons, the Xflea (rough translation: bridge hoppers, or colloquially, broppers) hold a race/ contest every Xflit (rough translation, 5 years, 8 months). The course consists of a isles connected by bridges. There is a start isle and a finish isle. A team consists of broppers who are all initially at the start isle and who try to get to the finish isle. Their movements are controlled by a gong; when the gong sounds, each bropper either stays put or crosses a bridge. The team goal is to get as many team members as possible to the finish. Being broppers, a team is of unbounded size, and the team has an unbounded amount of time to get from start to finish. Wait, somethings missing. We forgot to tell you about the bridges. Only one bropper can cross a bridge at a time (i.e., between one gong and the next gong), and the bridges are all 1-way. There are two kinds of bridges, F-bridges and S-bridges. An F-bridge, or falling bridge, falls down immediately after it is crossed, and cannot be used a second time. However S-bridges, or synchronized bridges, are another kettle of brop altogether. S-bridges do NOT fall down. But they can only be used if all S-bridges are crossed (by different broppers) simultaneously. That is, if at a gong some bropper tries to cross every S-bridge, they all succeed, but if some S-bridge has no bropper trying to cross it, none of the broppers trying to cross S-bridges go anywhere. Also, there no way for broppers to get from the end of any S-bridge to the beginning of some S-bridge, so a bropper cannot cross an S-bridge and then go to the beginning of some S-bridge to help other broppers across. The layout of the race/contest is different for every team. But this is not as unfair as it seems, as the course is always very large and random, and teams never get nearly as many members to the finish as they could in theory. Just to prove this, a team is told in advance the maximum number of members they could get from start to finish. And you have been hired to write a program which will compute this so the contest can be properly run. Input ----- For each of several test cases, one line containing the test case name, followed by lines that describe bridges. These have the form type begin end where type is `F' or `S' and begin and end are isle numbers. After these lines is a line containing just `.'. Isles are numbered 1, 2, 3, ..., N for some N <= 10,000. The start isle is always isle 1 and the finish is always isle 2. No S-bridge begins or ends at the start or finish isles, and no two S-bridges start at the same isle or finish at the same isle. There is at most one bridge with a given beginning isle and end isle (but there can be two bridges going in opposite directions between two isles). There are no more than 1,000,000 bridges, and no input line is longer than 80 characters. Input ends with an end of file. Output ------ For each test case, a copy of the test case name line, followed by a line containing just the maximum number of team members who can make it from start to finish. Note that a bropper who starts is not required to finish, but may drop out at any time (e.g., after crossing an S-bridge). Sample Input ------ ----- -- SAMPLE 1 -- F 1 3 F 1 5 F 5 2 S 3 4 S 5 6 . -- SAMPLE 2 -- F 1 3 F 1 5 F 5 2 F 4 2 S 3 4 S 5 6 . -- SAMPLE 3 -- F 1 3 F 1 5 F 5 2 F 4 2 F 6 2 S 3 4 S 5 6 . Sample Output ------ ------ -- SAMPLE 1 -- 1 -- SAMPLE 2 -- 1 -- SAMPLE 3 -- 2 Thanks: To the books of Iain M. Banks for stylistic guidance. File: broppers.txt Author: Bob Walton Date: Wed Oct 10 03:20:56 EDT 2012 The authors have placed this file in the public domain; they make no warranty and accept no liability for this file. RCS Info (may not be true date or author): $Author: walton $ $Date: 2012/10/10 07:23:26 $ $RCSfile: broppers.txt,v $ $Revision: 1.10 $